Doubt about CGridView and css

Hello friends

I use CGridView and its works ok, I change the file css that was created by Yii on assets folder, but I change the folder of my project, and Yii create another folder inside assets and back the css form originally. Why? How can i solve this?

my basic understanding:

  1. never ever change css file under yii assets folder, period.

  2. subfolder name of your css file under assets folder is hashed unique name from your original css path before it’s published to assets folder;

now, if you changed you original path of your css file, then yii will generate another unique-name sub-folder under assets.

so change the source not the destination (assets), if you css not be refreshed under your assets, you could always safely delete your assets folder and yii will automatically generate for you.

asset management is great feature to me when i start to learn yii

CGridView has its own default css file, that is ‘framework/zii/widgets/assets/gridview/style.css’.

And it will be copied to the assets folder.

As rootbear says, each file under the assets folder are not to be edited … it will someday be overwritten by the source.

And also you should not edit the default(source) css file under the framework folder.

If you want to use your customized css file for a CGridView …

[list=1]

[*]Copy the default(source) css file to your own folder that web server can access

[*]Edit the copy to satisfy your needs

[*]Set ‘cssFile’ property to the url of that copy

[/list]




$this->widget('zii.widgets.grid.CGridView', array(

	'id' => 'some-data-grid',

	'dataProvider' => $model->search(),

	'cssFile' => '/css/gridview/style.css',  // your version of css file

	...



If you want to use the customized css file for CGridView application wide, then you can set a widgetFactory property to set it in the main configuration file:




'widgetFactory'=>array(

	'widgets'=>array(

		'CGridView'=>array(

			'cssFile'=>'/css/gridview/style.css',  // your version of css file

		),

		...



Thank you. It solved the problem.

@softark, thanks, good to know widgetFactory.

thank you very much but what should be the relative path of this css file

I don’t know exactly what your concern is, but I think you should use an absolute path, because CGridView can be used in many places and the relative path to your css will vary from place to place.

ty friend! Very nice

Thank you so much but please change path

from


'cssFile' => '/css/gridview/style.css',  // your version of css file

to


'cssFile' => Yii::app()->request->baseUrl."/css/gridview/style.css",