cakephp:我可以在控制器内设置$ scripts_for_layout吗? [英] cakephp: can I set $scripts_for_layout from within a controller?

查看:80
本文介绍了cakephp:我可以在控制器内设置$ scripts_for_layout吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好
我想从控制器内设置布局的$ scripts_for_layout。
这是可能的,如果是怎么回事?

解决方案

简短的答案:也许你做错了。 / p>

答案:脚本不应该是控制器依赖的。



解决方法(因为有时你只需要):你可以设置in beforeRender a var:

  function beforeRender(){
parent :: beforeRender
$ this-> set('scripts',array('script1','script2'...));
}

在$ script的布局检查中添加它们。


Hi I'd like to set the layout's $scripts_for_layout from within the controller. Is this possible, and if yes how?

解决方案

Short answer: maybe you're doing it wrong.

Long answer: Scripts should not be controller dependent. It's 'theoretically' wrong, and cake does not like people who doesn't adhere to the mvc pattern.

Workaround (because sometimes you just need to): You can set in beforeRender a var:

function beforeRender() {
    parent::beforeRender();
    $this->set('scripts', array('script1', 'script2' ...));
}

And in the layout check for $scripts and add them.

这篇关于cakephp:我可以在控制器内设置$ scripts_for_layout吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆