Yaf_View_Simple::assign
(Yaf >=1.0.0)
Assign a variable to the view
Description
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.
Parameters
nameThe name under which the variable becomes available to the template, or an array of variables to assign.
valueThe value to assign.
Return Values
Returns true.
Examples
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"));
}
}
?>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>See Also
Yaf_View_Simple::assignRefYaf_View_Simple::clearYaf_View_Simple::get