July 1st in PHP Scripts by .

Custom Layouts with CakePHP Framework

I was amazed with the simplicity of the CakePHP framework. Its so easy to understand the model view controller and just within minutes we can break down the application like a blog into pieces.

Just i was experimenting i found that making custom layouts with the framework is bit hard to find after i made search in the web. I decided to publish here. You can download and install latest cakephp framework here: cakephp.org

Just a quick tip on basics of CakePHP Framework… You will see lot of files under the cakephp folder.

Model – It interacts/talks with your database like SQL queries. It is always singular like post.php

Controllers – It defines the basic logic of the application. Like you can add, delete, edit operations for a particular data. It is always written in plural form like posts_controller.php

Views – Basically shows how output is presented/

You should install in such a way that main page is /cakephp/app/webroot

To create a custom layout just look for folder named /cakephp/app/views/layouts. Just create a default layout and place it there. The file should be named default.thtml






Demo Header Page



Demo (c) Footer Page

once you create default layout page sure you have 2 php variables $content_for_layout and $title_for_layout there

You can create as many different layout and place them inside the layout folder. For a specific view to display the customized layout, make sure you include a line named in the controllers file like this.

var $layout = 'main';

inside your controllers code.

Similar Posts:

5 Comments

  • Baz L
    July 2, 2007
  • chiheb
    August 19, 2008
  • osama
    March 15, 2010
  • veacky
    May 19, 2010
  • Bruno Oliveira
    March 25, 2011

Leave A Comment.