Take the 2-minute tour ×

I am getting my foot wet with CakePHP and wondering what is better to load views. I tried searching but could not find satisfying answer for this small question. If I have to load header and footer along with content, what should be better approach :

1) Using $this->fetch("header") in view.ctp

or 2) I don't know how is it possible but, loading different views one after another from controller like we do in CodeIgniter ($this->load->view("header")).

share|improve this question
Most likely you'll want to use elements rather than blocks (as you mentioned in #1). Elements are probably the closest analog to what you mentioned in #2. book.cakephp.org/2.0/en/views.html#elements –  Kai Oct 16 '13 at 19:24
You should move away from the idea of rendering a "header" and "footer" separately, like Wordpress does. It's not a good practice, in my view, to hold those separately - they are designed together as HTML and should be held together. In MVC-like frameworks this is known as a layout, which is essentially the outer part of your document. In most frameworks there is a chunk of PHP added at content points, of which there is usually one. –  halfer Oct 16 '13 at 19:53
add comment

1 Answer

up vote 2 down vote accepted

As mentioned by user2076809, you'll probably want to use elements for this purpose, to keep things DRY: book.cakephp.org/2.0/en/views.html#elements.

Be aware though that Cake uses layouts (http://book.cakephp.org/2.0/en/views.html#layouts) to handle the header and footer by default, so take a look at app/View/Layouts/default.ctp and make sure you don't have redundant code there (for example, it has the <head> tag with all the default CSS includes).

share|improve this answer
and there is one $this->render('/Overviews/overview'); method as well I found. We don't have to make its use ? –  akshayb Oct 16 '13 at 19:36
add comment

Your Answer


