Hi, So I have a crm module that I want to be able to theme, but if i query Yii:app()->theme from within the module it returns null. How would u set a module specific theme, and where would you place the theme directory, in root/themes or in module/themes?
Hi!
I’ve developed something similar, I share themes between modules, so I’ve created a BaseWebModule component, from which I extend all my modules.
In my case, the problem was related to layout paths, not to Yii::app()->theme returning null
components/BaseWebModule.php
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
// this method is called before any module controller action is performed
// you may place customized code here
if(isset(Yii::app()->theme)):
$layoutPath=Yii::app()->theme->getBasePath().DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'layouts';
$this->setLayoutPath($layoutPath);
endif;
return true;
}
else
return false;
}
I also added the following to a custom component BaseController.php
public function init(){
Yii::app()->theme = Yii::app()->user->getCurrentTheme(); //do some logic to load the desired theme
}
Extended all my controllers from BaseController.php
I’ve put all my themes under webroot.themes
I think that it should work for you as the mechanism is almost the same
Hope this helps!
Regards!
