(Yaf >=1.0.0)
Yaf_View_Simple::render — Render a template
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.
tplThe path to the template, relative to the template directory set by Yaf_View_Simple::setScriptPath() or application.view.directory.
varsOptional 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>