CakePHP: How to Add Theme Support?
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.

Edit the file and just with two lines of code, add theme support on your application:
-
class AppController extends Controller {
-
var $view = 'Theme';
-
var $theme = 'default';
-
}
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.

Third!
Create another folder called default inside cake\app\views\themed, and place all your template files there.
This theme name is taken from
-
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
on March 30th, 2008 at 2:17 am
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
on March 30th, 2008 at 8:22 am
Thanks for your correction
on February 15th, 2009 at 10:30 pm
Interesting feature! I’m left with at least two key questions right off the top of my head, though:
(1) What about layouts?
(2) What about css?
Both of those assets determine the look of a Cake app, but they don’t fall under the /views/ folder. So, how do they play into this Theme support?
Thanks
on March 24th, 2009 at 8:19 pm
Hi,
Same question - this is nice to handle layouts - but how would you handle
e.g. allowing the user to pic their CSS scheme for the site?
on March 24th, 2009 at 9:11 pm
Layouts will be places on cake\app\views\themed\default\layouts.
While css and image files are in \app\webroot\themed\default\….
This way user can pick theme (Eg. default) and CakePHP will magically do the rest.
You only need to put files on proper folder.
Don’t forget! On production server, /webroot is set as the DocumentRoot.
So this way, we hide our php / cakephp script from public. Refer to this CakePHP Production Installation
User can only see \webroot\… but not \views\…
Anything inside views should NOT be visible to user.
So don’t put images inside \views\…, put in \webroot\ instead.