根据当前记录使用 CakePHP 自定义布局
有谁对如何不基于当前视图而是基于与视图关联的数据自定义站点范围内的布局有建议吗?在大多数情况下,我们使用的模型都有一个关联的俱乐部 ID,因此必须根据当前页面与哪个俱乐部关联来自定义布局标题图像、CSS 等。
这是我到目前为止的想法。 调用与当前控制器关联的模型中的函数,该函数为您提供布局参数。 在appController中,beforeRender中,设置俱乐部的布局参数。
这看起来不太优雅,因为每个模型都必须有这个函数,如果 beforeRender 在应用程序控制器中定义,我将如何调用正确的模型?
一些提示会很棒!
Does anyone have recommendations on how to customize the layout sitewide based not on the current view, but the data associated with the view? In most cases, the models we are using have an associated Club id, so would have to customize the layout header image, css, etc, depending on which Club the current page is associated with.
Here is what I am thinking so far.
Call a function in the model associated with the current controller, which gives you the layout parameters.
In appController, beforeRender, set layout parameters for the club.
This doesn't seem very elegant, because each model would have to have this function, and how would I call the right model if beforeRender is defined in the app controller?
Some tips would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
拉塞尔,
你可能想看看这个。
Russel,
you might want to look at this.
只需在名为“dashboard.ctp”的布局中创建一个文件,然后如果您的视图是索引,您的函数将是这样的...
重要的一行是 $this->layout = 'dashboard';
Simply create a file in layouts called "dashboard.ctp" then if your view is index, your function would be something like this...
The important line being $this->layout = 'dashboard';
我们最终要做的是在应用程序控制器中检查当前正在加载站点的域,然后根据此信息设置布局(为站点需要定制的每个域提供一个布局)。这不是一个很好的解决方案,但效果很好。
What we ended up doing is checking in the app controller for the domain the site is currently being loaded from, then setting the layout based on this information (have a layout for each domain the site needs to look customized for). Not a great solution but it works fine.