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

2 Comments so far »

  1. Template par défaut pour CakePHP pour votre site en CakePHP « Wareteam said,

    Wrote on November 3, 2008 @ 10:59 pm

    [...] CakePHP themes made easy Theming your CakePHP apps [...]

  2. Sistemas de Temas do CakePHP KISS - Keep it simple, stupid said,

    Wrote on November 28, 2008 @ 4:11 pm

    [...] Vocês podem encontrar um pouco de documentação no Book do CakePHP, mais informações no blog PseudoCoder.com e se ainda não estiver satisfeito, pode olhar o blog rodoTelmi. [...]

Comment RSS · TrackBack URI

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment: