问题
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