PHP - Manual: Yaf_View_Simple::assignRef
2024-11-15
(Yaf >=1.0.0)
Yaf_View_Simple::assignRef — The assignRef purpose
不同于Yaf_View_Simple::assign(),这个方法传递一个引用变量给模板引擎
name
一个字符串的名字,被用来传递值给模板。
value
mixed value
示例 #1 Yaf_View_Simple::assignRef()example
<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
$value = "bar";
$this->getView()->assign("foo", $value);
/* plz note that there was a bug before Yaf 2.1.4,
* which make following output "bar";
*/
$dummy = $this->getView()->render("index/index.phtml");
echo $value;
//prevent the auto-render
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
}
?>
示例 #2 template()example
<html>
<head>
<title><?php echo $foo; $foo = "changed"; ?></title>
</head>
<body>
</body>
</html>
以上例程的输出类似于:
/* access the index controller will result: */ changed
官方地址:https://www.php.net/manual/en/yaf-view-simple.assignref.php