CJuiWidget: Allow default theme specification across all widgets?


I’m noodling around with some CJuiWidgets, and I’m noticing they each of a member variable called $theme, which sets the jQuery theme to use.

I’d like to propose a method of setting the default theme across all widgets, preferably in a configuration file, so as to automatically theme the entire site in one fell swoop.

What I’ve done locally, and appears to work is:

In framework/zii/widgets/jui/CJuiWidget.php, in the init function:

 80     public function init()

 81     {

 82         if($this->theme == null)

 83         {

 84             $modules = Yii::app()->modules;

 85             if(array_key_exists('jui', $modules) && array_key_exists('defaultTheme', $modules['jui']))

 86             {

 87                 $this->theme = $modules['jui']['defaultTheme'];n

 88             }

 89             else

 90             {

 91                 $this->theme = 'base';

 92             }

 93         }


 95         $this->resolvePackagePath();

 96         $this->registerCoreScripts();

 97         parent::init();

 98     }

And then in config/main.php:

22     'modules'=>array(

23         'jui' => array(

24             'defaultTheme' => 'cupertino'

25             ),

26     ),

This doesn’t feel ideal, but it achieves the ability to centralize the default theme in what I feel is the right place (the config file). If there’s a better way of implementing this, please let me know.

Comments and critiques are welcome.

I think it can be useful. Please add it here so we’ll not forget to discuss/implement it: http://code.google.com/p/yii/

The above solution is better suited to be included in the core, because - in the customization case - all CJui… widgets has to be extended in order to inherit from the extended CJuiWidget.

In my opinion, the use of the module configuration array for this purpose may be questionable.

I added another possible solution here