本文整理匯總了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');
});
}