php8.5
Home/ Manual/ yaf / yaf_view_simple/ Yaf_View_Simple::__construct

Yaf_View_Simple::__construct

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Constructor of Yaf_View_Simple

Description

Yaf_View_Simple::__construct(string $template_dir, array $options = NULL)

Yaf_View_Simple is the default and only view engine Yaf supports out of the box. An instance is created automatically by the Yaf_Dispatcher when the application starts; instantiating it directly is only needed to render templates outside of the dispatch flow.

The template_dir argument must point to an existing directory containing the view scripts; it becomes the script path of the view and can later be changed with Yaf_View_Simple::setScriptPath.

Parameters

template_dir

The directory where the template scripts are stored.

options

Optional view options as an array. Reserved for custom view engine implementations; the built-in engine accepts but does not use it.

Return Values

No value is returned.

Examples

Yaf_View_Simple::__construct example

php
<?php
define("TEMPLATE_DIRECTORY", APPLICATION_PATH . '/views');
$view = new Yaf_View_Simple(TEMPLATE_DIRECTORY);
$view->assign("name", "world");
echo $view->render("greeting.phtml");
?>

See Also

  • Yaf_View_Simple::render
  • Yaf_View_Simple::display
  • Yaf_View_Simple::setScriptPath

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