本文整理汇总了PHP中Slim::view方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::view方法的具体用法?PHP Slim::view怎么用?PHP Slim::view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim
的用法示例。
在下文中一共展示了Slim::view方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setLayout
/**
* Set layout file
*/
function setLayout()
{
$this->slim->view()->setLayout($this->slim->config('layout.file') . '.php');
}
示例2: testSlimRenderSetsResponseStatusOk
/**
* Test Slim::render
*
* Pre-conditions:
* You have initialized a Slim app and render an existing
* template. No Exceptions or Errors are thrown.
*
* Post-conditions:
* The response status is 404;
* The View data is set correctly;
* The response status code is set correctly
*/
public function testSlimRenderSetsResponseStatusOk(){
$data = array('foo' => 'bar');
Slim::init();
Slim::render('test.php', $data, 404);
$this->assertEquals(Slim::response()->status(), 404);
$this->assertEquals($data, Slim::view()->getData());
$this->assertEquals(Slim::response()->status(), 404);
}
示例3: testViewDataTransfer
/**
* Test view data is transferred to newer view
*/
public function testViewDataTransfer()
{
$data = array('foo' => 'bar');
$s = new Slim();
$s->view()->setData($data);
$s->view('CustomView');
$this->assertSame($data, $s->view()->getData());
}
示例4: testSlimRenderSetsViewData
/**
* Test Slim sets view data when rendering
*
* Pre-conditions:
* You have initialized a Slim app and render an existing template
*
* Post-conditions:
* The render method passes array of data into View
*/
public function testSlimRenderSetsViewData()
{
Slim::init();
$data = array('foo' => 'bar');
Slim::render('test.php', $data);
$this->assertSame(Slim::view()->data(), $data);
}
示例5: Autoloader
require "libs/Simplepie/autoloader.php";
//Autoload para as Classes do SimplePie, para leitura de RSS
require "libs/Slim/Slim.php";
//Micro-framework Slim, para gerenciamento de rotas e alguns Helpers
include "app/funcoes.php";
//Funções próprias, como CSS, Javascript e Meta
include "app/config.php";
//Configurações gerais do sistema, através de Constantes.
date_default_timezone_set('America/Sao_Paulo');
$autoloader = new Autoloader();
$app = new Slim();
$app->contentType('text/html; charset=utf-8');
$app->add(new Slim_Middleware_SessionCookie(array('secret' => '98897qwer65465qwe9r79qw9e354as68dh56k6lks6df8g', 'expires' => '60 minutes')));
$authenticate = function ($app) {
return function () use($app) {
if (!isset($_SESSION['dehbora']['user'])) {
$_SESSION['dehbora']['urlRedirect'] = $app->request()->getPathInfo();
$app->flash('error', 'Você precisa se logar.');
$app->redirect(URL_BASE . '/inicial');
}
};
};
$app->hook('slim.before.dispatch', function () use($app) {
$user = null;
if (isset($_SESSION['dehbora']['user'])) {
$user = $_SESSION['dehbora']['user'];
}
$app->view()->setData('user', $user);
});
require_once "app/routes.php";
$app->run();
示例6: getShopDomain
if (strpos($key, "c_") !== false) {
$_SESSION["parameters"][$key] = $value;
}
}
// Initiate database object
$databaseParameters = array("user" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_user"] : "", "password" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_password"] : "", "host" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_host"] : "", "port" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_port"] : "", "database" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_schema"] : "");
$app->config("install.database.parameters", $databaseParameters);
$app->config('install.database', new Shopware_Install_Database($databaseParameters));
function getShopDomain()
{
$domain = $_SERVER["HTTP_HOST"];
$basepath = str_replace("/check/index.php", "", $_SERVER["SCRIPT_NAME"]);
return array("domain" => $domain, "basepath" => $basepath);
}
// Set global variables
$app->view()->setData("selectedLanguage", $selectedLanguage);
$app->view()->setData("language", $language);
$app->view()->setData("baseURL", str_replace("index.php", "", $_SERVER["PHP_SELF"]));
$app->view()->setData("app", $app);
$app->view()->setData("error", false);
$app->view()->setData("parameters", $_SESSION["parameters"]);
$basepath = getShopDomain();
$app->view()->setData("basepath", "http://" . $basepath["domain"] . $basepath["basepath"]);
// Step 1: Select language
$app->map('/', function () {
$app = Slim::getInstance();
$app = Slim::getInstance();
// Check system requirements
$shopwareSystemCheck = $app->config('install.requirements');
$systemCheckResults = $shopwareSystemCheck->toArray();
if ($shopwareSystemCheck->getFatalError() == true) {
示例7: testSlimFlashNow
/**
* Slim Flash Now
*
* Pre-conditions:
* Slim app sets Flash message for current request;
*
* Post-conditions:
* Message is persisted to View data;
*/
public function testSlimFlashNow()
{
$app = new Slim();
$app->get('/', function () use($app) {
$app->flashNow('info', 'Foo');
});
$app->run();
$flash = $app->view()->getData('flash');
$this->assertEquals('Foo', $flash['info']);
}
示例8: Slim
<?php
// require stuffs
require 'vendors/Slim/Slim/Slim.php';
require 'vendors/Slim-Extras/Views/MustacheView.php';
require 'vendors/couchsimple.php';
// set up the app
MustacheView::$mustacheDirectory = 'vendors';
$app = new Slim(array('view' => 'MustacheView'));
$env = $app->environment();
$app->view()->appendData(array('app_title' => 'Couchbase Beers', 'base_url' => $env['SCRIPT_NAME'], 'current_url' => $env['PATH_INFO']));
// Setup Couchbase connected objects
try {
$cb = new Couchbase("127.0.0.1:9000", "Administrator", "asdasd", "beer-sample");
} catch (ErrorException $e) {
die($e->getMessage());
}
$cbv = new CouchSimple(array('host' => '127.0.0.1', 'port' => 9500));
// openbeers application goodness
// GET route
$app->get('/', function () use($app) {
$content = $app->view()->render('index.mustache');
$app->render('layout.mustache', compact('content'));
});
// beer routes
require_once 'beers.php';
// brewery routes
require_once 'breweries.php';
// run, Slim, run
$app->run();
示例9: setLayout
/**
* Set layout file
*/
public function setLayout($layout)
{
$layoutFile = is_bool($layout) ? $this->slim->config('layout.file') . '.php' : $layout . ".php";
$this->slim->view()->setLayout($layoutFile);
}
示例10: define
define("ENV_TYPE", "prod");
}
$current_module_location = dirname($_SERVER["DOCUMENT_ROOT"] . $_SERVER["PHP_SELF"]);
if ($current_module_location == $_SERVER["DOCUMENT_ROOT"]) {
//root level
$current_module_location = $config["path_to_default_site_module"];
}
require_once $current_module_location . "/config.php";
//include all of the controller functions
include_all_files_in_directory($current_module_location . '/controllers');
//USE $config IN YOUR ROUTES!! Do not use module_config
$config = array_merge($config, $module_config);
$config["active_module"] = basename($current_module_location);
// Prepare app
$app = new Slim(array('view' => 'TwigView', 'templates.path' => $current_module_location . "/templates"));
$twig = $app->view()->getEnvironment();
$template_location_directories = array($current_module_location . "/templates", $config["path_to_default_site_module"] . "/templates", $_SERVER["DOCUMENT_ROOT"]);
$loader = new Twig_Loader_Filesystem($template_location_directories);
$twig->setLoader($loader);
foreach ($config as $var_name => $var_value) {
$twig->addGlobal($var_name, $var_value);
}
$twig->addGlobal("session", $_SESSION);
//create an array of all the modules
$modules_list_array = array();
if ($handle = opendir($_SERVER["DOCUMENT_ROOT"])) {
while (false !== ($entry = readdir($handle))) {
$module_config = false;
if ($entry != "." && $entry != ".." && is_dir($_SERVER["DOCUMENT_ROOT"] . "/" . $entry)) {
if (is_file($_SERVER["DOCUMENT_ROOT"] . "/" . $entry . "/config.php")) {
require $_SERVER["DOCUMENT_ROOT"] . "/" . $entry . "/config.php";
示例11: testSlimCopiesViewData
/**
* Test Slim copies data from old View to new View
*
* Pre-conditions:
* You have intialized a Slim app with a View;
* You set data for the initial View;
* You tell Slim to use a new View
*
* Post-conditions:
* The data from the original view should be accessible
* in the new View
*/
public function testSlimCopiesViewData()
{
$data = array('foo' => 'bar');
Slim::init();
Slim::view()->setData($data);
Slim::view('CustomView');
$this->assertEquals($data, Slim::view()->getData());
}