How much code is ok in a CakePHP Layout?

99封情书 提交于 2019-12-13 04:41:50

问题


So, I'm starting out on my first Cake app, enjoying it so far and I've almost finished the first part of my app. I'm just now tidying up my code and making sure it's done the Cake way.

I know Cake like to have code in certain places, e.g. the fat model, skinny controller ethic, but how about in a layout?

I have a nav bar at the top of each page. The links are populated by the current controller and passed to the view in an array which arranges them in the nav bar.

Currently I have an ->extend in every view to pull this bar in, but that's repetition and I want to remove it.

My 2 options (I think unless there's another way).... Code this nav bar directly in the layout. I'm not sure about doing this, not sure if you're supposed to but a lot of non-presentation code in the layout.

Or, I could create an element, have the code there and include it in the layout.

Which is the Cakeiest way of achieving this?

来源:https://stackoverflow.com/questions/26224845/how-much-code-is-ok-in-a-cakephp-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!