PHP 8.6.0 Beta 3 is available for testing

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

本次渲染要导出到视图脚本的变量关联数组。

返回值

成功时返回渲染结果(string),失败时返回 false

示例

示例 #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);
    }
}
?>

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top