本文整理汇总了PHP中Slim\Slim::view方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::view方法的具体用法?PHP Slim::view怎么用?PHP Slim::view使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Slim
的用法示例。
在下文中一共展示了Slim::view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @return $this
*/
public function run()
{
$this->routes = Yaml::parse(file_get_contents(__DIR__ . '/../config/routes.yml'))['routes'];
$this->config = Yaml::parse(file_get_contents(__DIR__ . '/../config/config.yml'));
$this->app = new \Slim\Slim(['view' => new Twig()]);
$this->app->view()->parserOptions = ['debug' => true];
$this->app->view()->parserExtensions = [new TwigExtension(), new \Twig_Extensions_Extension_Text(), new \Twig_Extensions_Extension_Array(), new \Twig_Extensions_Extension_Date(), new \Twig_Extensions_Extension_I18n(), new \Twig_Extensions_Extension_Intl()];
$this->app->view()->setTemplatesDirectory(__DIR__ . '/Views/');
$this->instantiateRoutes()->app->run();
return $this;
}
示例2: configureView
protected function configureView()
{
$view = $this->app->view();
$view->parserOptions = array('debug' => true, 'cache' => sys_get_temp_dir());
$view->parserExtensions = array(new \Slim\Views\TwigExtension(), new TwigExtension($this), new \Twig_Extension_Debug());
/** @var \Twig_Environment $twig */
$twig = $view->getInstance();
/** @var \Twig_Loader_Filesystem $loader */
$loader = $twig->getLoader();
$loader->addPath($this->options['root.dir'] . "/lib/Pasls/TDK/templates");
}
示例3: __construct
private function __construct()
{
// Prepare app
$this->slim = new \Slim\Slim(array('templates.path' => self::$templatePath));
// Prepare view
$this->slim->view(new \Slim\Views\Twig());
$this->slim->view->parserOptions = array('charset' => 'utf-8', 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$this->slim->view->parserExtensions = array(new \Slim\Views\TwigExtension());
if (self::$debug) {
$this->slim->view->parserExtensions[] = new \Twig_Extension_Debug();
}
$this->slim->add(new \Slim\Middleware\SessionCookie());
}
示例4: getFramework
protected function getFramework($config)
{
$app = new Slim(['view' => new Twig()]);
$app->config(['templates.path' => $config['templates.path']]);
$view = $app->view();
$view->parserOptions = $config['parserOptions'];
$view->parserExtensions = array(new TwigExtension());
return $app;
}
示例5: testNoDataAppendedIfProfileKeyDoesNotExist
public function testNoDataAppendedIfProfileKeyDoesNotExist()
{
$app = new Slim();
$app->view(new SlimView());
$mw = new Profile(array());
$mw->setApplication($app);
$mw->setNextMiddleware($app);
$mw->call();
$data = $app->view()->getData('profile');
$this->assertEmpty($data);
}
示例6: __construct
public function __construct()
{
$slim = new Slim(['view' => new Twig()]);
$slim->config(['templates.path' => __DIR__ . '/../../view']);
$slim->view()->parserOptions = array('debug' => true, 'cache' => __DIR__ . '/../../compilation_cache');
$slim->config(['content' => ['main_menu' => $this->getMainMenu()]]);
global $config;
ORM::configure("mysql:host={$config['host']};port={$config['port']};dbname={$config['db_name']}");
ORM::configure('username', $config['db_user']);
ORM::configure('password', $config['db_password']);
ORM::configure('driver_options', [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
ORM::configure('error_mode', PDO::ERRMODE_EXCEPTION);
$this->initSlimRoute();
}
示例7: register
public function register(Slim $app)
{
$app->container->singleton('cache', function () {
return new FilesystemCache('tmp/cache/db');
});
$app->container->singleton('connection', function () {
$dbOptions = (require 'config/connection.config.php');
$config = new Configuration();
return DriverManager::getConnection($dbOptions, $config);
});
$app->container->singleton('log', function () {
$logger = new Logger('echale-gas');
$logger->pushHandler(new StreamHandler('tmp/logs/app.log', LogLevel::DEBUG));
return $logger;
});
$app->container->singleton('paginator', function () use($app) {
return new PagerfantaPaginator($app->config('defaultPageSize'));
});
$app->container->singleton('paginatorFactory', function () use($app) {
return new PaginatorFactory($app->paginator);
});
$app->container->singleton('proxiesConfiguration', function () use($app) {
$config = new ProxyConfiguration();
$config->setProxiesTargetDir('tmp/cache/proxies');
spl_autoload_register($config->getProxyAutoloader());
return $config;
});
$app->urlHelper = new TwigExtension();
$app->container->singleton('twig', function () use($app) {
$twig = new Twig();
$twig->parserOptions = ['charset' => 'utf-8', 'cache' => realpath('tmp/cache/twig'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true];
$twig->parserExtensions = [$app->urlHelper, new HalRendererExtension()];
return $twig;
});
$app->container->singleton('controllerEvents', function () use($app) {
$eventManager = new EventManager();
// Ensure rendering is performed at the end by assigning a very low priority
$eventManager->attach('postDispatch', new RenderResourceListener($app->twig), -100);
$eventManager->attach('renderErrors', new RenderErrorsListener($app->twig), -100);
return $eventManager;
});
$app->container->singleton('controller', function () use($app) {
$controller = new RestController($app->request(), $app->response());
$factory = new RestControllerProxyFactory($app->proxiesConfiguration, $app->controllerEvents);
$controller = $factory->createProxy($controller);
$factory->addEventManagement($controller);
return $controller;
});
$app->view($app->twig);
}
示例8: setup
/**
* Setup the template service.
*
* @param \Slim\Slim $app The application instance.
*/
public static function setup(Slim $app)
{
$debug = $app->config('debug');
$view = $app->view(new Twig());
$view->parserOptions = ['debug' => $debug, 'cache' => $app->config('view.cache_path')];
$view->setTemplatesDirectory($app->config('view.path'));
$view->parserExtensions = [new TwigExtension()];
if ($debug) {
$view->parserExtensions[] = new Twig_Extension_Debug();
}
$extensions = (array) $app->config('view.extensions');
foreach ($extensions as $ext) {
$view->parserExtensions[] = new $ext();
}
}
示例9: newInstance
public static function newInstance(\Slim\Slim $app)
{
try {
$config = $app->config('connection');
$instance = new \PDO("mysql:host={$config['mysql']['host']};dbname={$config['mysql']['database']}", $config['mysql']['user'], $config['mysql']['password'], $config['mysql']['options']);
if (!empty($config['mysql']['execute'])) {
foreach ($config['mysql']['execute'] as $sql) {
$stmt = $instance->prepare($sql);
$stmt->execute();
}
}
} catch (\PDOException $p) {
//$this->slim->log->error('BAD THINGS');
return $app->halt(500, $app->view()->fetch('error/500.php'));
}
return $instance;
}
示例10: prepareWebResultView
/**
* This function adds the clickable labels with alternate formats to the results webpage
*
* @return void
*/
protected function prepareWebResultView()
{
// mime type buttons
// TODO:
// get mimetypes of the current route and
// only output the buttons for the allowed mimetypes of that route
// $currentRouteAcceptableMimeTypes = $this->app->router()->getCurrentRoute();
// $formats = (isset($this->routeInfo->mimeTypes) ? $this->routeInfo->mimeTypes : $this->mimeLabels);
$formats = $this->mimeLabels;
// we are viewing a html page, so remove this result format
// unset($formats['text/html']);
$this->app->view()->set('alternate_formats', $formats);
//set the current selected mime type
$this->app->view()->set('current_mime', $this->mimeBest);
// inject javascript
$this->app->view()->set('javascript', '<script src="' . $this->app->request()->getRootUri() . '/assets/js/web-result.js" type="text/javascript"></script>');
}
示例11: configureApp
protected function configureApp(Slim $app, Container $c)
{
// Add Middleware
$app->add($c['profileMiddleware']);
$app->add($c['navigationMiddleware']);
$app->add($c['authenticationMiddleware']);
$app->add($c['sessionCookieMiddleware']);
// Prepare view
$app->view($c['twig']);
$app->view->parserOptions = $this['config']['twig'];
$app->view->parserExtensions = array($c['slimTwigExtension'], $c['twigExtensionDebug']);
$config = $this['config'];
// Dev mode settings
$app->configureMode('development', function () use($app, $config) {
$app->config(array('log.enabled' => true, 'log.level' => Log::DEBUG));
$config['twig']['debug'] = true;
});
}
示例12: __construct
/**
* Portfolio constructor.
* @param array $config
*/
public function __construct(array $config)
{
Portfolio::$app = $this;
$this->config = $config;
$this->slim = new \Slim\Slim(['view' => new \Slim\Views\Twig()]);
$this->slim->view()->parserOptions = array('debug' => $config['debug'], 'cache' => $config['twig']['cacheDir']);
$this->slim->view()->parserExtensions = array(new \Slim\Views\TwigExtension());
$this->slim->view()->setTemplatesDirectory($config['twig']['templatesDir']);
$this->client = new \ApiClient\Client($config['vk']);
$this->storage = new \Storage\Storage(new \Predis\Client($config['redis']));
$group = $this->storage->getById(new \Model\Group(), -$config['vk']['owner_id']);
$this->slim->view()->appendData(['Group' => $group]);
$this->slim->view()->appendData(['Meta' => $this->getMetaData($config['meta'])]);
}
示例13: _slimApp
protected function _slimApp()
{
$this['view'] = function () {
// Configure Twig view for slim
$view = new Twig();
$view->parserOptions = array('charset' => 'utf-8', 'cache' => XHGUI_ROOT_DIR . '/cache', 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
return $view;
};
$this['app'] = $this->share(function ($c) {
$app = new Slim($c['config']);
// Enable cookie based sessions
$app->add(new SessionCookie(array('httponly' => true)));
// Add renderer.
$app->add(new Xhgui_Middleware_Render());
$view = $c['view'];
$view->parserExtensions = array(new Xhgui_Twig_Extension($app));
$app->view($view);
return $app;
});
}
示例14: Slim
/**
* Created by PhpStorm.
* @author : Verem Dugeri
* Date: 10/8/15
* Time: 9:30 AM
*/
require_once 'vendor/autoload.php';
use Slim\Slim;
use Verem\Emoji\Api\AuthController;
use Verem\Emoji\Api\EmojiController;
use Verem\Emoji\Api\DAO\UserManager;
use Verem\Emoji\Api\Exceptions\RecordNotFoundException;
$app = new Slim(['templates.path' => 'templates/', 'debug' => true]);
// Prepare view
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
//route middleware
$authenticator = function () use($app) {
$response = $app->response();
$response->header("Content-type", "application/json");
//determine if the user has authorization.
$authorization = $app->request->headers->get('Authorization');
if (!is_null($authorization)) {
//check token expiry
$manager = new UserManager();
try {
$user = $manager->where('token', '=', $authorization);
if ($user['token_expire'] < date('Y-m-d H:i:s')) {
$response->body(json_encode(['status' => 401, 'message' => 'You have no authorization']));
示例15: Slim
//Specify the location of the translation tables
bindtextdomain('BachViewer', APP_DIR . '/locale');
bind_textdomain_codeset('BachViewer', 'UTF-8');
//Choose domain
textdomain('BachViewer');
/** /I18n stuff */
$app = new Slim(array('debug' => APP_DEBUG, 'view' => new Twig(), 'templates.path' => APP_DIR . '/views'));
$app_base_url = '';
if (strncmp($_SERVER['PHP_SELF'], '/index.php', strlen('/index.php')) && strncmp($_SERVER['PHP_SELF'], '/debug.php', strlen('/debug.php'))) {
preg_match('/.*(index|debug)\\.php/', $_SERVER['PHP_SELF'], $matches);
if (isset($matches[0])) {
$app_base_url = $matches[0];
}
}
$viewer = new Viewer($conf, $app_base_url);
$view = $app->view();
$view->parserExtensions = array(new Twig_Extensions_Extension_I18n());
if (defined('APP_CACHE') && APP_CACHE !== false) {
$view->parserOptions = array('cache' => APP_CACHE, 'auto_reload' => true);
}
if (!defined('DEFAULT_PICTURE')) {
define('DEFAULT_PICTURE', 'main.jpg');
}
$app->hook('slim.before.dispatch', function () use($app, $conf, $lang, $app_base_url) {
//let's send view parameters before dispatching
$v = $app->view();
$ui = $conf->getUI();
$v->setData('app_base_url', $app_base_url);
$v->setData('app_web_url', str_replace(array('/index.php', '/debug.php'), array('', ''), $app_base_url));
$v->setData('enable_right_click', $ui['enable_right_click']);
$v->setData('lang', $lang);