Yaf_View_Simple::render

(Yaf >=1.0.0)

Yaf_View_Simple::renderRender a template

Опис

public function Yaf_View_Simple::render(string $tpl, array $vars = NULL): string

Renders a template and returns the result as a string. The template is included as a plain PHP script, so any PHP code in it is executed, and assigned variables are available under their names.

Зауваження:

Unlike Yaf_View_Simple::display(), the result is returned instead of being appended to the Yaf_Response_Abstract body.

Параметри

tpl

The path to the template, relative to the template directory set by Yaf_View_Simple::setScriptPath() or application.view.directory.

vars

Optional variables to assign for this render; they override assigned variables with the same name.

Значення, що повертаються

The rendered result as a string, or false on failure.

Приклади

Приклад #1 Yaf_View_Simple::render() example

<?php
class ProductController extends Yaf_Controller_Abstract
{
    public function detailAction()
    {
        /* render the template and post-process the result */
        $html = $this->getView()->render("product/detail.phtml", array(
            "name"  => "Yaf in Action",
            "price" => "29.90",
        ));

        $this->getResponse()->setBody($html);
        return false; // skip auto-rendering
    }
}
?>

Приклад #2 Template example

<h1><?php echo $name; ?></h1>
<p>Price: <?php echo $price; ?> EUR</p>

Поданий вище приклад виведе щось схоже на:

<h1>Yaf in Action</h1>
<p>Price: 29.90 EUR</p>

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top