php8.5
Home/ Manual/ yaf / yaf_controller_abstract/ Yaf_Controller_Abstract::render

Yaf_Controller_Abstract::render

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Render view template

Description

Yaf_Controller_Abstract::render(string $tpl, [array|null $parameters]): string|bool|null

Renders the view script tpl and returns the output, unlike Yaf_Controller_Abstract::display.

Parameters

tpl

The view script name, relative to the view path.

parameters

An associative array of variables to export to the view script for this rendering.

Return Values

The rendered output as a String on success, or false on failure.

Examples

Yaf_Controller_Abstract::render example

php
<?php
class ProductController extends Yaf_Controller_Abstract
{
    public function indexAction() {
        // do not auto-render the default template
        Yaf_Dispatcher::getInstance()->disableView();

        // render product/index.phtml and return the output
        // instead of sending it directly (as display() would)
        $html = $this->render("product/index.phtml", array(
            "products" => array("yaf", "php"),
        ));

        // post-process and set it as the response body
        $this->getResponse()->setBody($html);
    }
}
?>

See Also

  • Yaf_Controller_Abstract::display
  • Yaf_Dispatcher::autoRender

Source: reference/yaf/yaf_controller_abstract/render.xml · from the official PHP manual (php/doc-en)