PHP 8.6.0 Beta 3 is available for testing

Yaf_View_Simple::render

(Yaf >=1.0.0)

Yaf_View_Simple::renderRender a template

Descrizione

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.

Nota:

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

Elenco dei parametri

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.

Valori restituiti

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

Esempi

Example #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
    }
}
?>

Example #2 Template example

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

Il precedente esempio visualizzerà qualcosa simile a:

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

Vedere anche:

add a note

User Contributed Notes

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