本文整理汇总了PHP中Phalcon\Mvc\View::setVar方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setVar方法的具体用法?PHP View::setVar怎么用?PHP View::setVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\View
的用法示例。
在下文中一共展示了View::setVar方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeRender
/**
* Before render
*
* @param PEvent $event
* @param PView $view
* @return PView
*/
public function beforeRender($event, $view)
{
$view->setVar('_limit', $view->getDI()->get('config')->pagination->limit);
if (isset($view->_sortColumn) && isset($view->_filter)) {
$filter = array_column($view->_sortColumn, 'filter');
if (!empty($filter)) {
$filterForm = new ZFormFilter($filter, $view->_filter);
$view->setVar('_filterColumn', $filterForm->getForm());
}
}
$view->setVar('_toolbarHelpers', ZToolbarHelper::getInstance($this->moduleBaseName, $view->getControllerName()));
}
示例2: beforeRender
/**
* Before render view
*
* @param PEvent $event
* @param PView $view
*/
public function beforeRender(PEvent $event, PView $view)
{
$defaultTemplate = $view->getDI()->get("config")->frontendTemplate->defaultTemplate;
$viewDir = ROOT_PATH . "/app/templates/frontend/" . $defaultTemplate . "/modules/" . $this->moduleBaseName . "/";
$pathView = $viewDir . $view->getControllerName() . "/" . $view->getActionName();
$view->setVar("_templateDir", ROOT_PATH . "/app/templates/frontend/" . $defaultTemplate);
if (realpath($pathView . ".volt")) {
$view->setViewsDir($viewDir);
}
}
示例3: registerViewService
/**
* @param \Phalcon\DI\FactoryDefault $di
*/
protected function registerViewService($di)
{
/**
* Setting up the view component
*/
$di['view'] = function () use($di) {
/*
* Obtengo el nombre del modulo para poder obner el archivo de configuracion
*/
$module = $this->name;
$this->layout_dir = '../../../../public/layouts/' . $di->get('modules')->{$module}->layout . '/';
$view = new View();
$view->setViewsDir($this->path . $this->view_dir);
$view->setLayoutsDir($this->layout_dir);
$view->setTemplateAfter($this->template);
$view->setVar('project-setting', $di->get('config')->project->toArray());
/*
* Registra Constantes de Modulo
*/
$view->setVar('module-setting', $di->get('modules')->{$module}->toArray());
// Set the engine
$view->registerEngines(array(".mustache" => function ($view, DI $di) {
$module = $this->name;
$partial_url = '../public/layouts/' . $di->get('modules')->{$module}->layout . '/partials';
$partial_loader = new Mustache_Loader_FilesystemLoader($partial_url);
$config = $di->get('config')->cache->frontend;
if ($config->active == 0) {
$options = array('partials_loader' => $partial_loader);
} else {
$options = array('cache' => '/var/www/var/cache/elephant', 'cache_file_mode' => $config->mode, 'partials_loader' => $partial_loader, 'strict_callables' => $config->callables);
}
$mustache = new Mustache($view, $di, $options);
return $mustache;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
};
}
示例4: compile
public function compile(JsUtils $js = NULL, View $view = NULL)
{
$result = $this->getTemplate();
foreach ($this as $key => $value) {
if (PhalconUtils::startsWith($key, "_") === false && $key !== "events") {
if (is_array($value)) {
$v = PropertyWrapper::wrap($value, $js);
} else {
$v = $value;
}
$result = str_ireplace("%" . $key . "%", $v, $result);
}
}
if (isset($js)) {
$this->run($js);
}
if (isset($view) === true) {
$controls = $view->getVar("q");
if (isset($controls) === false) {
$controls = array();
}
$controls[$this->identifier] = $result;
$view->setVar("q", $controls);
}
return $result;
}
示例5: createVoltVars
/**
*/
protected function createVoltVars()
{
$config = $this->getConfig();
$this->view->setVar('ngAppName', $config->get('ng.app.name'));
}
示例6: function
return $url;
});
/**
* Setting the View and View Engines
*/
$di->setShared('view', function () use($config, $di, $eventsManager) {
$view = new View();
$view->registerEngines(['.volt' => function ($view, $di) use($config) {
$volt = new Volt($view, $di);
$path = APPLICATION_ENV == APP_TEST ? DOCROOT . 'tests/_cache/' : DOCROOT . $config->get('volt')->cacheDir;
$options = ['compiledPath' => $path, 'compiledExtension' => $config->get('volt')->compiledExt, 'compiledSeparator' => $config->get('volt')->separator, 'compileAlways' => APPLICATION_ENV !== APP_PRODUCTION];
$volt->setOptions($options);
$volt->getCompiler()->addFunction('strtotime', 'strtotime')->addFunction('sprintf', 'sprintf')->addFunction('str_replace', 'str_replace')->addFunction('is_a', 'is_a');
return $volt;
}, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
$view->setVar('version', Version::get())->setViewsDir(DOCROOT . $config->get('application')->viewsDir);
$eventsManager->attach('view', function ($event, $view) use($di, $config) {
/**
* @var \Phalcon\Events\Event $event
* @var \Phalcon\Mvc\View $view
*/
if ($event->getType() == 'notFoundView') {
$message = sprintf('View not found - %s', $view->getActiveRenderPath());
throw new Exception($message);
}
});
$view->setEventsManager($eventsManager);
return $view;
});
/**
* Database connection is created based in the parameters defined in the configuration file
示例7: testViewOptions
public function testViewOptions()
{
$config = array('cache' => array('service' => 'otherCache'));
$date = date("r");
$content = '<html>' . $date . '</html>' . PHP_EOL;
$di = $this->_getDi('otherCache');
$view = new View($config);
$view->setDI($di);
$view->setViewsDir('unit-tests/views/');
$view->setVar("date", $date);
$view->start();
$view->cache(true);
$view->render('test8', 'other');
$view->finish();
$this->assertEquals($view->getContent(), $content);
$view->reset();
sleep(1);
$view->setVar("date", date("r"));
$view->start();
$view->cache(true);
$view->render('test8', 'other');
$view->finish();
$this->assertEquals($view->getContent(), $content);
}
示例8: testVoltMacrosIssue11771
public function testVoltMacrosIssue11771()
{
$this->specify("Volt macros can't accept objects", function () {
$this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
Di::reset();
$view = new View();
$di = new Di();
$di->set('escaper', function () {
return new Escaper();
});
$di->set('tag', function () {
return new Tag();
});
$di->set('url', function () {
return (new Url())->setBaseUri('/');
});
$view->setDI($di);
$view->setViewsDir(PATH_DATA . 'views/');
$view->registerEngines(array('.volt' => function ($view, $di) {
return new Volt($view, $di);
}));
$object = new \stdClass();
$object->foo = "bar";
$object->baz = "buz";
$object->pi = 3.14;
$object->ary = ["some array"];
$object->obj = clone $object;
$view->setVar('object', $object);
$view->start();
$view->render('macro', 'list');
$view->finish();
ob_start();
var_dump($object);
$actual = ob_get_clean();
// Trim xdebug first line (file path)
$actual = substr($actual, strpos($actual, 'class'));
$expected = substr($view->getContent(), strpos($view->getContent(), 'class'));
expect($actual)->equals($expected);
$form = new Form();
$form->add(new Password('password'));
$view->setVar('formLogin', $form);
$view->start();
$view->render('macro', 'form_row');
$view->finish();
$actual = <<<FORM
<div class="form-group">
<label class="col-sm-2 control-label" for="password">password:</label>
<div class="col-sm-6"><input type="password" id="password" name="password" class="form-control " /></div>
</div>
FORM;
expect($actual)->equals($view->getContent());
$this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
});
}
示例9: renderToolbar
/**
* @return string
*/
public function renderToolbar()
{
$view = new View();
$viewDir = __DIR__ . '/views/';
$view->setViewsDir($viewDir);
$view->setVar('debugWidget', $this);
$content = $view->getRender('toolbar', 'index');
return $content;
}
示例10: testVoltEngineBuiltInFunctions
public function testVoltEngineBuiltInFunctions()
{
@unlink('unit-tests/views/test11/index.volt.php');
$di = new Phalcon\DI();
$view = new Phalcon\Mvc\View();
$view->setDI($di);
$view->setViewsDir('unit-tests/views/');
$view->registerEngines(array('.volt' => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
$view->setVar('arr', array(1, 2, 3, 4));
$view->setVar('obj', new SomeObject(array(1, 2, 3, 4)));
$view->setVar('str', 'hello');
$view->setVar('no_str', 1234);
$view->start();
$view->render('test11', 'index');
$view->finish();
$this->assertEquals($view->getContent(), 'Length Array: 4Length Object: 4Length String: 5Length No String: 4Slice Array: 1,2,3,4Slice Array: 2,3Slice Array: 1,2,3Slice Object: 2,3,4Slice Object: 2,3Slice Object: 1,2Slice String: helSlice String: elSlice String: lloSlice No String: 123Slice No String: 23Slice No String: 34');
}
示例11: testViewOptions
public function testViewOptions()
{
$this->specify("Views are not cached properly when passing options to the constructor", function () {
$this->_clearCache();
$config = array('cache' => array('service' => 'otherCache'));
$date = date("r");
$content = '<html>' . $date . '</html>' . PHP_EOL;
$di = $this->_getDi('otherCache');
$view = new View($config);
$view->setDI($di);
$view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
$view->setVar("date", $date);
$view->start();
$view->cache(true);
$view->render('test8', 'other');
$view->finish();
expect($view->getContent())->equals($content);
$view->reset();
sleep(1);
$view->setVar("date", date("r"));
$view->start();
$view->cache(true);
$view->render('test8', 'other');
$view->finish();
expect($view->getContent())->equals($content);
});
}