Yaf_Controller_Abstract::render
(Yaf >=1.0.0)
Yaf_Controller_Abstract::render — 渲染视图模板
说明
protected function Yaf_Controller_Abstract::render(string
$tpl, ?array $parameters = ?): string|bool|null
渲染视图脚本 tpl 并返回其输出,这点与
Yaf_Controller_Abstract::display() 不同。
参数
tpl
视图脚本名,相对于视图路径。
parameters
本次渲染要导出到视图脚本的变量关联数组。
示例
示例 #1 Yaf_Controller_Abstract::render() 示例
<?php
class ProductController extends Yaf_Controller_Abstract
{
public function indexAction() {
// 不自动渲染默认模板
Yaf_Dispatcher::getInstance()->disableView();
// 渲染 product/index.phtml 并返回输出,
// 而不是像 display() 那样直接发送
$html = $this->render("product/index.phtml", array(
"products" => array("yaf", "php"),
));
// 后处理后设置为响应主体
$this->getResponse()->setBody($html);
}
}
?>来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
