PHP-ist: All about learning PHP, frameworks, tips and tricks

PHP4, PHP5, cakephp, codeigniter, code example (scriptlets / snipplets) and many easy and effective way to learn

CakePHP: How to Add Theme Support?

Posted in cakephp by PHP-ist on the February 7th, 2008

Now with CakePHP v1.2 (beta) we can easily add theme with its ThemeView class.
This guide about how to add theme into fresh CakePHP installation will be explained in very basic step-by-step . I learn it frrom here.
Updated: sample code provided

Download code example, extract inside CakePHP root.

First!
Create a file called app_controller.php inside cake\app\controllers.
Create CakePHP AppController
Edit the file and just with two lines of code, add theme support on your application:

PHP:
  1. class AppController extends Controller {
  2.     var $view = 'Theme';
  3.     var $theme = 'default';
  4. }

Second!
You need to put all your theme collections inside a folder called themed instead views. This folder doesn't exists yet, so go to cake\app\views and create new folder themed inside it.
Create themed folder inside view

Third!
Create another folder called default inside cake\app\views\themed, and place all your template files there.
This theme name is taken from

PHP:
  1. var $theme = 'default';

We can just create another folder and activate it very easily thanks to ThemeView class.

That's it now you have an application that support theme. Easy?! Yea, that was sooo Cake :)

Tags: php4, cakephp, code example

2 Responses to 'CakePHP: How to Add Theme Support?'

Subscribe to comments with RSS or TrackBack to 'CakePHP: How to Add Theme Support?'.

  1. majic3 said,

    on March 30th, 2008 at 2:17 am

    folder called themed instead views

    instead should read inside?

    Themes are great I had a play with them a while back, found it perfect for making admin interface entirely separate from the public site. Had some issues when using it in conjunction with assetmapper, but since cake now has settings for asset compression in core.php I am revisiting this

  2. PHP-ist said,

    on March 30th, 2008 at 8:22 am

    …put inside folder “views/themed/”, instead “views/”.

    Thanks for your correction :)

Leave a Reply




Cannot find your answer here?
Feel free to get in touch and ask PHP-ist anything, just anything :)