本文整理汇总了PHP中Phalcon\Mvc\View\Engine\Volt类的典型用法代码示例。如果您正苦于以下问题:PHP Volt类的具体用法?PHP Volt怎么用?PHP Volt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Volt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerServices
public function registerServices(\Phalcon\DiInterface $di = null)
{
/**
* Read configuration
*/
$config = (include dirname(dirname(dirname(__DIR__))) . "/apps/config/config.php");
$di->set('dispatcher', function () use($di) {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
return $dispatcher;
}, true);
$di->set('view', function () use($config) {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->registerEngines(array('.volt' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
return $volt;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
});
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use($config) {
return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, 'charset' => 'utf8'));
};
}
示例2: registerServices
/**
* Register specific services for the module
* @param \Phalcon\DiInterface $di
*/
public function registerServices(DiInterface $di)
{
$config = $this->_config;
$configShared = $di->get('config');
$vDI = $di;
//Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Cnab');
return $dispatcher;
});
//Registering the view component
$di->set('volt', function ($view, $vDI) use($config, $configShared) {
$volt = new Volt($view, $vDI);
$volt->setOptions(array('compiledPath' => $configShared->volt->path, 'compiledExtension' => $configShared->volt->extension, 'compiledSeparator' => $configShared->volt->separator, 'stat' => (bool) $configShared->volt->stat));
$compiler = $volt->getCompiler();
//Add funcao
$compiler->addFunction('is_a', 'is_a');
return $volt;
});
/**
* Configura o serviço de view
*/
$di->set('view', function () use($config, $vDI) {
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->registerEngines(array('.volt' => 'volt'));
return $view;
});
return $di;
}
示例3: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di Dependency Injection Container
*/
public function registerServices(DiInterface $di)
{
/**
* Read configuration
*/
$config = (require __DIR__ . "/config/config.php");
/**
* Setting up the view component
*/
$di->setShared('view', function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->setTemplateBefore('main');
$view->registerEngines([".volt" => function ($view, $di) {
$volt = new Volt($view, $di);
$volt->setOptions(['compiledPath' => function ($templatePath) {
return realpath(__DIR__ . "/../../var/volt") . '/' . md5($templatePath) . '.php';
}, 'compiledExtension' => '.php', 'compiledSeparator' => '%']);
return $volt;
}]);
return $view;
});
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di->setShared('db', function () use($config) {
return new Connection(['host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname]);
});
}
示例4: setView
private function setView($manager, $theme)
{
/* ==================================================
* ตั้งค่าเรียกใช้งานไฟล์ View ทั้งหมด
* Setting up the view component
* ================================================== */
$manager->set('view', function () use($theme) {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
/* ตำแหน่งเก็บไฟล์ views ทั้งหมด */
$view->setLayoutsDir(sprintf('%s/%s/', $this->config->theme->themesDir, $theme));
/* ตำแหน่งเก็บไฟล์ layouts ทั้งหมด */
$view->setTemplateAfter('layouts/' . $this->layoutName);
/* เลือกไฟล์ layout เริ่มต้น*/
/* สร้างโฟล์เดอร์เก็บไฟล์ cache */
$cacheDir = sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName);
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}
$view->registerEngines(array('.phtml' => function ($view, $di) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName), 'compiledSeparator' => '_'));
return $volt;
}));
return $view;
});
}
示例5: registerServices
/**
* Register specific services for the module
*/
public function registerServices(DiInterface $di)
{
// Assign our new tag a definition so we can call it
$di->set('Utilitarios', function () {
return new \Ecommerce\Admin\Helpers\UtilitariosHelper();
});
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Ecommerce\\Admin\\Controllers');
return $dispatcher;
});
// Registering the view component
$di->set('view', function () {
$config = (include __DIR__ . "/config/config.php");
$view = new View();
$view->registerEngines(array('.volt' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
return $volt;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
$view->setViewsDir('../apps/admin/views/');
return $view;
});
include "../apps/admin/vendor/autoload.php";
}
示例6: registerServices
public function registerServices(DiInterface $di)
{
global $config;
$di->setShared('url', function () use($config) {
$url = new UrlResolver();
$url->setBaseUri($config->backend->baseUri);
return $url;
});
$di->setShared('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers");
return $dispatcher;
});
$di->setShared('view', function () use($config) {
$view = new View();
$view->setViewsDir($config->backend->viewsDir);
$view->setLayoutsDir('layouts/');
$view->setPartialsDir('partials/');
$view->registerEngines(array('.phtml' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->backend->cacheDir, 'compiledSeparator' => '_'));
return $volt;
}, '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
});
}
示例7: registerViewFunctions
/**
* register custom volt function to use in frontend
*
* @param $view
* @param array $functions
*/
public static function registerViewFunctions(Volt &$view, array $functions = [])
{
$compiler = $view->getCompiler();
foreach ($functions as $name => $body) {
$compiler->addFunction($name, $body);
}
}
示例8: registerServices
/**
* Register specific services for the module
*/
public function registerServices(DiInterface $di)
{
$config = $di->get('config');
//Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Promoziti\\Modules\\Business\\Controllers");
return $dispatcher;
});
$di->set('view', function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->registerEngines(array('.volt' => function ($view, $di) {
$volt = new VoltEngine($view, $di);
$config = $di->get('config');
$volt->setOptions(array('compileAlways' => true, 'compiledPath' => $config->application->cache_dir . "volt/", 'compiledSeparator' => '_'));
return $volt;
}));
return $view;
});
$di->set('aws_s3', function () use($config) {
//version 2.7 style
$s3 = \Aws\S3\S3Client::factory(array('key' => $config->application->security->aws->key, 'secret' => $config->application->security->aws->secret, 'region' => 'us-west-2', 'version' => '2006-03-01'));
return $s3;
});
}
示例9: factory
/**
* Create view instance.
* If no events manager provided - events would not be attached.
*
* @param DIBehaviour $di DI.
* @param Config $config Configuration.
* @param string|null $viewsDirectory Views directory location.
* @param Manager|null $em Events manager.
*
* @return View
*/
public static function factory($di, $config, $viewsDirectory = null, $em = null)
{
$view = new View();
$volt = new Volt($view, $di);
$volt->setOptions(["compiledPath" => $config->application->view->compiledPath, "compiledExtension" => $config->application->view->compiledExtension, 'compiledSeparator' => $config->application->view->compiledSeparator, 'compileAlways' => $config->application->debug && $config->application->view->compileAlways]);
$compiler = $volt->getCompiler();
$compiler->addExtension(new Extension());
$view->registerEngines([".volt" => $volt])->setRenderLevel(View::LEVEL_ACTION_VIEW)->restoreViewDir();
if (!$viewsDirectory) {
$view->setViewsDir($viewsDirectory);
}
// Attach a listener for type "view".
if ($em) {
$em->attach("view", function ($event, $view) use($di, $config) {
if ($config->application->profiler && $di->has('profiler')) {
if ($event->getType() == 'beforeRender') {
$di->get('profiler')->start();
}
if ($event->getType() == 'afterRender') {
$di->get('profiler')->stop($view->getActiveRenderPath(), 'view');
}
}
if ($event->getType() == 'notFoundView') {
throw new Exception('View not found - "' . $view->getActiveRenderPath() . '"');
}
});
$view->setEventsManager($em);
}
return $view;
}
示例10: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Read configuration
*/
$config = (include APP_PATH . "/apps/frontend/config/config.php");
/**
* Setting up the view component
*/
$di['view'] = function () use($config) {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->registerEngines(array('.html' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
return $volt;
}));
return $view;
};
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use($config) {
$config = $config->database->toArray();
$dbAdapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config['adapter'];
unset($config['adapter']);
return new $dbAdapter($config);
};
$di['wechat'] = 'App\\Libs\\Wechat';
$di['config'] = $config;
}
示例11: registerServices
/**
* Register specific services for the module
*/
function registerServices(\Phalcon\DiInterface $di)
{
//Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
return $dispatcher;
});
$config = $di->getShared('config');
$di->set('view', function () use($config, $di) {
$view = new View();
$router = $di->getShared('router');
/*
* @todo 给layouts等目录统一变量
* */
$view->setViewsDir(__DIR__ . '/views/');
$view->setLayoutsDir('/../../../layouts/');
// 多模块的话, 可能会有多个风格,所以需要切换layout,这里的Path是根据当前module的Path向上走的
$view->setLayout('index');
$view->registerEngines(array('.volt' => function ($view, $di) use($config) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
return $volt;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
}, true);
}
示例12: factory
/**
* Create view instance.
* If no events manager provided - events would not be attached.
*
* @param DIBehaviour $di DI.
* @param Config $config Configuration.
* @param string $viewsDirectory Views directory location.
* @param Manager|null $em Events manager.
*
* @return View
*/
public static function factory($di, $config, $viewsDirectory, $em = null)
{
$view = new PhView();
$volt = new PhVolt($view, $di);
$volt->setOptions(["compiledPath" => $config->global->view->compiledPath, "compiledExtension" => $config->global->view->compiledExtension, 'compiledSeparator' => $config->global->view->compiledSeparator, 'compileAlways' => $config->global->view->compileAlways]);
$compiler = $volt->getCompiler();
$compiler->addExtension(new EnViewExtension());
$compiler->addFilter('floor', 'floor');
$compiler->addFunction('range', 'range');
$compiler->addFunction('in_array', 'in_array');
$compiler->addFunction('count', 'count');
$compiler->addFunction('str_repeat', 'str_repeat');
$view->registerEngines(['.volt' => $volt])->setRenderLevel(PhView::LEVEL_ACTION_VIEW)->setViewsDir($viewsDirectory);
// Attach a listener for type "view".
if ($em) {
$em->attach("view", function ($event, $view) use($di, $config) {
if ($config->global->profiler && $di->has('profiler')) {
if ($event->getType() == 'beforeRender') {
$di->get('profiler')->start();
}
if ($event->getType() == 'afterRender') {
$di->get('profiler')->stop($view->getActiveRenderPath(), 'view');
}
}
if ($event->getType() == 'notFoundView') {
throw new Exception('View not found - "' . $view->getActiveRenderPath() . '"');
}
});
$view->setEventsManager($em);
}
$di->set('view', $view);
return $view;
}
示例13: register
/**
* Register services
*/
public function register()
{
$this->container->set('volt', function ($view, $di) {
$volt = new VoltEngine($view, $di);
$volt->setOptions($this->config->volt->toArray());
return $volt;
});
}
示例14: __construct
/**
* Constructor
* Initializes simple view
*
* @param null $options
*/
public function __construct($options = null)
{
parent::__construct($options);
$this->registerEngines(array('.volt' => function ($this, $di) use($options) {
$volt = new PhalconView\Engine\Volt($this, $di);
$volt->setOptions(array('compiledPath' => $options['cacheDir'], 'compiledSeparator' => '_'));
return $volt;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
}
示例15: attachVoltService
public function attachVoltService($voltCacheDir)
{
$this->_di->set('voltService', function ($view, $di) use($voltCacheDir) {
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions(['compiledPath' => $voltCacheDir, 'compiledSeparator' => '_', 'compiledExtension' => '.compiled']);
return $volt;
});
return $this;
}