« Yaf_View_Simple::assign
Yaf_View_Simple::clear »

Yaf_View_Simple::assignRef

(Yaf >=1.0.0)

Yaf_View_Simple::assignRef — The assignRef purpose

説明

public function Yaf_View_Simple::assignRef(string $name, mixed &$value): bool

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 テンプレートの例

<html>
 <head>
  <title><?php echo $foo;  $foo = "changed"; ?></title>
 </head>  
<body>
</body>
</html>

上の例の出力は、 たとえば以下のようになります。

/* index コントローラにアクセスしたときの結果 */
changed

参考

関連キーワード:
View   assignRef   assign   代入   index   エンジン   テンプレート   getView   head   title   changed   body   clear   mixed   IndexController   extends   Controller   Abstract   indexAction   バグ   dummy   render   phtml   レンダリング   無効
関連する関数・ページ:
yaf-view-simple.assign   yaf-view-simple.set   yaf-view-simple.clear   class.yaf-view-simple   yaf-view-simple.construct   yaf-view-simple.getscriptpath