©
Ce document utilise Manuel du site Web PHP chinois Libérer
(Yaf >=1.0.0)
Yaf_View_Simple::assign — 为视图引擎分配一个模板变量
$name
[, mixed $value
] )为视图引擎分配一个模板变量
name
字符串或者数组
如果为字符串, 则$value不能为空
value
mixed value
Example #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" ));
}
?>
Example #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>