本文整理汇总了PHP中Phalcon\Mvc\View::setLayout方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setLayout方法的具体用法?PHP View::setLayout怎么用?PHP View::setLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\View
的用法示例。
在下文中一共展示了View::setLayout方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* @param Event $event
* @param Application $application
* @return mixed
*/
public function boot(Event $event, Application $application)
{
$config = $application->getConfig()->application;
if (isset($config->view) && $config->view !== false) {
$view = new View();
$view->setViewsDir($config->view->viewsDir);
$view->setLayoutsDir($config->view->layoutsDir);
$view->setLayout($config->view->layout);
$application->getDI()->setShared('view', $view);
}
}
示例2: 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);
}
示例3: setView
private function setView()
{
$view = new View();
$view->setViewsDir($this->config->application->viewsDir);
$view->setLayoutsDir('layouts/');
$view->setLayout('index');
$view->registerEngines(['.volt' => $this->setVolt($view), '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
return $view;
}
示例4: render
/**
* @param string $layout
*
* @return string
*/
public function render($layout = 'edit')
{
$column = $this->_params->getParam('name');
$prefix = $this->_params->getParam('source');
$fieldId = ($prefix ? $prefix . '_' : '') . $column;
$fieldName = $prefix ? $prefix . '[' . $column . ']' : $column;
$defaultParams = $this->_params->getParams();
unset($defaultParams['name']);
$tagParams = array_merge([$fieldName], $this->_params->getParam('tag', []), ['value' => $this->getValue(), 'id' => $fieldId] + $defaultParams);
$this->_params->setParam('id', $fieldId);
// все параметры уже добавлены, в общем списке они не нужны
unset($tagParams['tag']);
$tagParams['class'] = isset($tagParams['class']) ? $tagParams['class'] . ' form-control' : 'form-control';
$layout = $this->_params->getParam('options.layout', $layout);
$this->beforeRender($tagParams);
$this->_view->setLayout($layout);
$this->_view->setVars(['field' => $this, 'model' => $this->_model, 'params' => $this->_params, 'tag' => $tagParams]);
return $this->_view->getRender($this->getLayoutDir($layout), $layout);
}
示例5: function
});
/**
* The URL component is used to generate all kind of urls in the application
*/
$di->set('url', function () use($config) {
$url = new UrlResolver();
$url->setBaseUri($config->application->baseUri);
return $url;
}, true);
/**
* Setting up the view component
*/
$di->set('view', function () use($config) {
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->setLayout('default');
$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);
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di->set('db', function () use($config) {
return new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname));
});
/**
* If the configuration specify the use of metadata adapter use it or use memory otherwise
示例6: testOverrideLayout
public function testOverrideLayout()
{
$view = new Phalcon\Mvc\View();
$view->setViewsDir('unit-tests/views/');
//Override controller layout
$view->start();
$view->setLayout('test6');
$view->render('test3', 'other');
$view->finish();
$this->assertEquals($view->getContent(), '<html>Well, this is the view content: here.</html>' . PHP_EOL);
}
示例7: function
/**
* If the configuration specify the use of metadata adapter use it or use memory otherwise
*/
$di->set('modelsMetadata', function () {
return new MetaDataAdapter();
});
/**
* Start the session the first time some component request the session service
*/
$di->set('session', function () {
$session = new SessionAdapter();
$session->start();
return $session;
});
$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('adminCommon');
$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);
示例8: testLayoutAndPick
public function testLayoutAndPick()
{
$view = new View();
$view->setViewsDir('unit-tests/views/');
// Pick string
$view->start();
$view->setLayout('test6');
$view->pick('test3/other');
$view->render('test3', 'another');
$view->finish();
$this->assertEquals($view->getContent(), '<html>Well, this is the view content: here.</html>' . PHP_EOL);
// Pick array
$view->start();
$view->setLayout('test6');
$view->pick(array('test3/other'));
$view->render('test3', 'another');
$view->finish();
$this->assertEquals($view->getContent(), '<html>Well, this is the view content: here.</html>' . PHP_EOL);
}
示例9: testLayoutAndPick
/**
* Test using different layout and pick
*
* @author Andres Gutierrez <andres@phalconphp.com>
* @since 2013-01-07
*/
public function testLayoutAndPick()
{
$this->specify('Using different layout and pick does not work as expected', function () {
$view = new View();
$view->setDI(Di::getDefault());
$view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
$view->start();
$view->setLayout('test6');
$view->pick('test3/other');
$view->render('test3', 'another');
$view->finish();
expect($view->getContent())->equals("<html>Well, this is the view content: here.</html>\n");
$view->start();
$view->setLayout('test6');
$view->pick(['test3/other']);
$view->render('test3', 'another');
$view->finish();
expect($view->getContent())->equals("<html>Well, this is the view content: here.</html>\n");
});
}