(Yaf >=1.0.0)
Yaf_View_Simple::assignRef — assignRef 的用途
與 Yaf_View_Simple::assign() 不同,此方法會將一個參考值賦值給引擎。
name
一個字串名稱,將在模板中用於存取該值。
value
混合類型值
範例 #1 Yaf_View_Simple::assignRef() 範例
<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
$value = "bar";
$this->getView()->assign("foo", $value);
/* 請注意,在 Yaf 2.1.4 之前有一個錯誤,
* 會使以下輸出為 "bar";
*/
$dummy = $this->getView()->render("index/index.phtml");
echo $value;
//防止自動渲染
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
}
}
?>
範例 #2 template() 範例
<html>
<head>
<title><?php echo $foo; $foo = "changed"; ?></title>
</head>
<body>
</body>
</html>
上述範例將輸出類似以下的內容
/* access the index controller will result: */ changed