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

Yaf_View_Simple::assignRef

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Alias of Yaf_View_Simple::assign

Description

Yaf_View_Simple::assignRef(string $name, mixed $value): bool

Assigns a variable to the view by reference. Unlike Yaf_View_Simple::assign, the value is passed by reference, so later changes to the caller's variable become visible to the template.

Parameters

name

The name under which the variable becomes available to the template.

value

The value to assign.

Return Values

Returns true.

Examples

Yaf_View_Simple::assignRef example

php
<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $value = "bar";
        $this->getView()->assignRef("foo", $value);

        /* later changes to $value are visible in the template,
         * because the variable was assigned by reference */
        $value = "changed";

        //prevent the auto-render
        Yaf_Dispatcher::getInstance()->autoRender(false);
    }
}
?>

Template example

php
<html>
 <head>
  <title><?php echo $foo; ?></title>
 </head>
 <body>
 </body>
</html>

The above example will output something similar to:

output
/* accessing the index controller will result: */
changed

See Also

  • Yaf_View_Simple::assign
  • Yaf_View_Simple::clear
  • Yaf_View_Simple::get

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