PHP 8.6.0 Beta 3 is available for testing

Yaf_View_Simple::assignRef

(Yaf >=1.0.0)

Yaf_View_Simple::assignRefAlias of Yaf_View_Simple::assign

Опис

public function 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.

Параметри

name

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

value

The value to assign.

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

Returns true.

Приклади

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

<?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);
    }
}
?>

Приклад #2 Template example

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

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

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

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

add a note

User Contributed Notes

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