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

Yaf_Controller_Abstract::display

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Render and display a view

Description

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

Renders the view script tpl and sends the result directly, unlike Yaf_Controller_Abstract::render, which returns the rendered output instead. Auto-rendering of the default action template is controlled by Yaf_Dispatcher::autoRender.

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, overriding those assigned through the view engine.

Return Values

Returns true on success, or false / null on failure.

Examples

Yaf_Controller_Abstract::display example

php
<?php
class ProductController extends Yaf_Controller_Abstract
{
    public function listAction() {
        // render product/list.phtml and send the result directly
        // to the client, exporting $products to this rendering
        $this->display("product/list.phtml", array(
            "products" => array("yaf", "php"),
        ));
    }
}
?>

Template example

php
<!-- application/views/product/list.phtml -->
<ul>
<?php foreach ($products as $product) { ?>
    <li><?php echo $product; ?></li>
<?php } ?>
</ul>

The above example will output something similar to:

output
<ul>
    <li>yaf</li>
    <li>php</li>
</ul>

See Also

  • Yaf_Controller_Abstract::render
  • Yaf_Dispatcher::autoRender

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