/** * 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())); }
/** * 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); } }
/** * @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; }; }
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; }
/** */ protected function createVoltVars() { $config = $this->getConfig(); $this->view->setVar('ngAppName', $config->get('ng.app.name')); }
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
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); }
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']); }); }
/** * @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; }
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'); }
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); }); }