PHP 8.6.0 Beta 3 is available for testing

Yaf_View_Simple::assign

(Yaf >=1.0.0)

Yaf_View_Simple::assignAssign a variable to the view

Beschreibung

public function Yaf_View_Simple::assign(mixed $name, mixed $value = NULL): bool

Assigns a variable to the view. Assigned variables are available to the template under their names. When called with a single array argument, every key/value pair is assigned, with the keys becoming the variable names.

Parameter-Liste

name

The name under which the variable becomes available to the template, or an array of variables to assign.

value

The value to assign.

Rückgabewerte

Returns true.

Beispiele

Beispiel #1 Yaf_View_Simple::assign() example

<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $this->getView()->assign("foo", "bar");
        $this->_view->assign(array("key" => "value", "name" => "value"));
    }
}
?>

Beispiel #2 Template example

<html>
 <head>
  <title><?php echo $foo; ?></title>
 </head>
 <body>
  <?php
    foreach ($this->_tpl_vars as $name => $value) {
        echo $$name; // or echo $this->_tpl_vars[$name];
    }
  ?>
 </body>
</html>

Siehe auch

add a note

User Contributed Notes

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