Archive for October, 2008

CakePHP themes made easy

CakePHP Logo
Another great features of this great framework, yes themes. My past client need dynamic theme plug into his website on each user login, with this cake feature it’s easy to implement

here’s the step:

class AppController extends Controller {
    ...
    var $view = 'Theme';
    ...
    function beforeRender() {
    ...
       $theme = $this->Auth->user('theme');
       if($userData) {
          $this->theme = $theme; 
       } else {
	   $this->theme = 'default';
       }
    ...
    }
}

so where the setting saved for each user ?, users model.
Based on this tutorial add theme field on users table

`theme` char(10) NOT NULL

next create folder name it as “themed” in webroot, and views

views/themed/ur_theme_name/
webroot/themed/ur_theme_name/

you can theme your layout, view, css, js, img; just create needed folder to create new themes
ex:

views/themed/ur_theme_name/index.ctp
views/themed/ur_theme_name/news.ctp
webroot/themed/ur_theme_name/css/user.css
webroot/themed/ur_theme_name/js/user.js

CakePHP theme tutorial
Theming your CakePHP apps (V1.2), Theming With CakePHP