Solarmd
(Neagamaxim)
June 26, 2012, 6:18pm
1
Hello,
Is there any way to define a global CSS for a Yii-based application?
The only known way for me to include a CSS file is the following:
Yii::app()->clientScript->registerCssFile('/store/css/form.css', 'screen, projection');
However for a global CSS this needs to be called in every action of a SiteController.
Thank you in advance.
yugenekr
(Yugenekr)
June 27, 2012, 6:26am
2
Hi,
I think the main approaches are:
Link global style in your layout file (or in _header.php if you have several layouts, including it in each layout file).
Register global style in components/Controller.php file and extend all controllers from this class.
Seems, all other variations using yii and available script-minimisation extensions just modifications of these approaches.
Solarmd
(Neagamaxim)
June 27, 2012, 9:09am
3
Thank you, registering CSS in the SiteController’s init() worked just fine for my case:
class SiteController extends CController
{
public function init()
{
// Apply global css
Yii::app()->clientScript->registerCssFile('/store/css/global.css', 'screen, projection');
}
}