Q:

Using layouts/elements in Cakephp

I am developing a webapp using Cakephp. I have created a default layout for the website. I created sections like header, footer, content.
Now some of the pages in my content section have same structure. These are part of a controller with various views defined for each page. What view template should I be using here? Layouts or Elements? 
In case I use layout, I will be using the controller to decide the layout I will use, but won't that change the layout for whole website?
Regards

A:

This is really a matter of preference.  I try to think of layout as the "structure" of the page -- so a header, placeholder for left nav, placeholder for top nav, footer.  That kind of thing.  I define those sections in the layout.
I'd recommend the "pages in my content section [that] have the same structure" be your layout.  As you mentioned, you can switch layouts in the controller, but any similarly structured pages (pages that will look the same as each other once you've removed the content) I would have share a layout.
Another example of layout switching could be for logged in versus anonymous users.  For a logged in user, websites frequently put a "Welcome, $name" message at the top, along with links to My Account, sign out, etc.  I often find myself using a different layout for logged in versus anon users.  ALso, in that situation, I use the beforeFilter() method to set the layout for a given controller, since I know whether the user is logged in or not when that callback is executed.
Sorry for the rambling, but this is a bit of a gray area (when to use a layout versus different elements).

