CakePHP:覆盖视图元素的模板变量
我在视图中使用视图元素,并且需要覆盖在控制器中设置的模板变量。我将键值数组传递到元素中,但对于该键没有任何效果。其他变量,在我可以在元素内部使用之前未定义。有什么技巧可以做到这一点还是我需要另一个变量来做到这一点?
内部控制器
$this->set('mykey', 'myvalue');
内部模板
echo $this->element('myelement', array('mykey' => 'anothervalue'));
有什么想法吗?
I'm using an viewelement inside a view and I need to override a templatevariable which was set in the controller. I pass a key-value-array into the element, but for that key it has no effect. Other variables, which are not defined before I can use inside the element. Is there a trick to do that or do I need another variable for that?
Inside Controller
$this->set('mykey', 'myvalue');
Inside Template
echo $this->element('myelement', array('mykey' => 'anothervalue'));
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚测试了您所描述的设置,并且使用第二个元素参数设置的变量而不是控制器中设置的变量。因此,“myelement”与预期的“anothervalue”相呼应。
可能是该元素 已启用缓存,但您必须指定它作为
$this->element()
调用的参数。I've just tested the setup you've described and the variable set by the second element parameter is used instead of the variable set in the controller. So "myelement" echoes "anothervalue" as is expected.
It could be that element caching is enabled, though you have to specify this as a parameter for the
$this->element()
call.