本文整理汇总了PHP中Phalcon\Mvc\View::getPartial方法的典型用法代码示例。如果您正苦于以下问题:PHP View::getPartial方法的具体用法?PHP View::getPartial怎么用?PHP View::getPartial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\View
的用法示例。
在下文中一共展示了View::getPartial方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: testPartials
public function testPartials()
{
$view = new View();
$view->setBasePath(__DIR__ . '/../');
$view->setViewsDir('unit-tests/views/');
$view->setParamToView('cool_var', 'le-this');
// Single partial
$view->start();
$view->render('test5', 'index');
$view->finish();
$this->assertEquals($view->getContent(), '<html>Hey, this is a partial, also le-this</html>' . PHP_EOL);
// Multiple partials
$view->start();
$view->render('test9', 'index');
$view->finish();
$this->assertEquals($view->getContent(), '<html>Hey, this is a partial, also le-this<br />Hey, this is a second partial, also le-this</html>' . PHP_EOL);
// A partial within other partial
$view->start();
$view->render('test5', 'subpartial');
$view->finish();
$this->assertEquals('<html>Including Hey, this is a partial, also le-this</html>' . PHP_EOL, $view->getContent());
// Single partial in overridden main view
$view->setMainView('html5');
$view->start();
$view->render('test5', 'index');
$view->finish();
$this->assertEquals('<!DOCTYPE html><html>Hey, this is a partial, also le-this</html>' . PHP_EOL, $view->getContent());
// Retrieve a partial as a string
$this->assertEquals('Hey, this is a partial, also le-this', $view->getPartial('partials/_partial1', array('cool_var' => 'le-this')));
}
示例3: testRenderingWithPartials
/**
* Tests rendering with partials
*
* @author Andres Gutierrez <andres@phalconphp.com>
* @since 2012-05-28
*/
public function testRenderingWithPartials()
{
$this->specify('The rendering with partials does not work as expected', function () {
$view = new View();
$view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
$view->setParamToView('cool_var', 'le-this');
$view->start();
$view->render('test5', 'index');
$view->finish();
expect($view->getContent())->equals("<html>Hey, this is a partial, also le-this</html>\n");
$view->start();
$view->render('test9', 'index');
$view->finish();
expect($view->getContent())->equals("<html>Hey, this is a partial, also le-this<br />Hey, this is a second partial, also le-this</html>\n");
$view->start();
$view->render('test5', 'subpartial');
$view->finish();
expect($view->getContent())->equals("<html>Including Hey, this is a partial, also le-this</html>\n");
$view->setMainView('html5');
$view->start();
$view->render('test5', 'index');
$view->finish();
expect($view->getContent())->equals("<!DOCTYPE html><html>Hey, this is a partial, also le-this</html>\n");
expect($view->getPartial('partials/_partial1', ['cool_var' => 'le-this']))->equals('Hey, this is a partial, also le-this');
});
}