Last active
December 22, 2015 09:58
-
-
Save rootbear/6455201 to your computer and use it in GitHub Desktop.
yii: specify per module theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TestModule extends CWebModule | |
{ | |
public function init() | |
{ | |
$this->setImport(array( | |
'tmp.models.*', | |
'tmp.components.*', | |
)); | |
//add this line to here to specify per module theme! | |
Yii::app()->theme = 'selected-theme-name'; | |
//register assets used in this module only | |
$this->register('example.css'); | |
$this->register('scroll.css'); | |
$this->register('scroll.js'); | |
} | |
// ... | |
public static function register($file) | |
{ | |
//could be module's assets path, in this case use vendor's assets as is | |
$assets_path_css = 'application.vendor.scrolljs.css'; | |
$assets_path_js = 'application.vendor.scrolljs.js'; | |
if(strpos($file, 'js') !== false){ | |
$url = Yii::app()->getAssetManager()->publish( | |
Yii::getPathOfAlias($assets_path_js)); | |
$path = $url . '/' . $file; | |
return Yii::app()->clientScript->registerScriptFile($path); | |
}else if(strpos($file, 'css') !== false){ | |
$url = Yii::app()->getAssetManager()->publish( | |
Yii::getPathOfAlias($assets_path_css)); | |
$path = $url . '/' . $file; | |
return Yii::app()->clientScript->registerCssFile($path); | |
} | |
return $path; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment