本文整理汇总了PHP中Phalcon\Mvc\View::setDI方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setDI方法的具体用法?PHP View::setDI怎么用?PHP View::setDI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\View
的用法示例。
在下文中一共展示了View::setDI方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initView
/**
* Init view (Phalcon Volt Template)
*
* @return View
*/
private function _initView()
{
$view = new View();
$view->setDI(Di::getDefault());
$view->registerEngines(['.volt' => function ($view, $di) {
$volt = new VoltEngine($view, $di);
$volt->setOptions(['compiledPath' => function ($templatePath) {
$templatePath = strstr($templatePath, '/app');
$dirName = dirname($templatePath);
if (!is_dir(ROOT_PATH . '/cache/volt' . $dirName)) {
mkdir(ROOT_PATH . '/cache/volt' . $dirName, 0755, true);
}
return ROOT_PATH . '/cache/volt' . $dirName . '/' . basename($templatePath, '.volt') . '.php';
}, 'compiledSeparator' => '_', 'compileAlways' => true, 'stat' => false]);
$compiler = $volt->getCompiler();
$compiler->addFunction('__', '__');
return $volt;
}]);
return $view;
}
示例2: testGetActiveRenderPath
/**
* @covers \Phalcon\Mvc\View::getActiveRenderPath
*/
public function testGetActiveRenderPath()
{
$di = new \Phalcon\Di();
$listener = new ViewAfterRenderListener();
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('view', $listener);
$view = new View();
$view->setDI($di);
$view->setEventsManager($eventsManager);
$view->setBasePath(__DIR__ . '/../');
$view->setViewsDir('unit-tests/views/');
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$view->start();
$view->render('test15', 'index');
$view->finish();
$expectedPath = realpath('unit-tests/views/');
$this->assertEquals($expectedPath . DIRECTORY_SEPARATOR . 'test15' . DIRECTORY_SEPARATOR . 'index.phtml', realpath($view->getContent()));
}
示例3: getRender
/**
* {@inheritdoc}
*/
public function getRender($template = null, array $params = [])
{
$this->isInitialized || $this->initialize();
if (empty($template)) {
$className = (new \ReflectionObject($this))->getShortName();
$template = mb_strtolower($className);
}
$view = new View();
$view->setDI($this->getDI());
$view->setViewsDir($this->getViewPath());
return $view->getPartial($template, array_merge($this->getViewParams(), $params));
}
示例4: 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);
}
示例5: 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']);
});
}
示例6: 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');
}
示例7: ytestCacheMethods
public function ytestCacheMethods()
{
$this->specify("View methods don't return the View instance", function () {
$di = $this->_getDi();
$view = new View();
$view->setDI($di);
$view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
expect($view->start())->equals($view);
expect($view->cache(true))->equals($view);
expect($view->render('test2', 'index'))->equals($view);
expect($view->finish())->equals($view);
});
}