There are many ways in Yii to get CSS on your pages.
The problem is that after you start using extensions, widgets, themes, etc., they all have their own stylesheets (fairly fair) and the order in which CSS is processed and inserted into the HTML depends on whether they were set in the controller, viewing or arranging or using the Yii asset manager or the Yii package manager.
Recently, our Yii project has been modified to use packages registered in config/main.php
as follows:
'clientScript'=>array( 'packages'=> array( 'theme'=>array( 'basePath'=>'yii.themes.default', 'css'=>array('css/reset.css','css/main.css','css/form.css'), 'js'=>array('js/lib.js'), 'depends'=>array('jquery'), ), ...
This caused the CSS file to crash because it was designed to override grid styles and was now included in the CGridView stylesheet.
The solution was to add these lines at the bottom of layouts/main.php
:
$path = Yii::getPathOfAlias('yii.themes.default').'/css/style.css'; $cssFile = Yii::app()->getAssetManager()->publish($path); Yii::app()->getClientScript()->registerCssFile($cssFile);
For me this seems like a less perfect solution, and I expect that we may have problems in the future when we forget what we have done, or we need to do something similar with another topic or another project completely.
Is there a better way to effectively manage CSS when it can be provided from many different sources?
Edit:
I am considering expanding CClientScript to provide an โoverrideโ option in which you can specify an array of CSS files to be included after registering the file. It looks like it might be a little flaky, though ...