How to define a global CSS?

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.

Hi,

I think the main approaches are:

  1. Link global style in your layout file (or in _header.php if you have several layouts, including it in each layout file).

  2. 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.

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');

	}

}