CakeFest 2024: The Official CakePHP Conference

Yaf_View_Simple::assignRef

(Yaf >=1.0.0)

Yaf_View_Simple::assignRefThe assignRef purpose

説明

public 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

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top