Yii Assets

Hi,

I working in a project where i have to deploy project files in installer. but i have make some changes in zii grid view layout.

So each and every time when i install my project, zii grid layout change to its default layout (blue header).

Please anyone can help me how to layout zii grid view permanently means it will not change its layout on new server

Thanks in advance :)

Dear Friend

We can copy the folder framework/zii/widgets/grid/gridview.

Put the contents inside the webroot/css folder.

You can remove the jquery.yiigridview.js inside the folder.

You can make modification there in styles.css file.

Now in admin.php we have set the cssFile Path.





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

	'id'=>'alphabet-grid',

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

	'filter'=>$model,

	'cssFile'=>'css/gridview/styles.css',

	'columns'=>array(


.........................................................



But every admin.php, we have to do this modification if you want the changes and changes to persist.

Regards.

You could also simply created a new class like this, and use that instead of CGridView

protected/components/GridView.php

[CODE]<?php

class GridView extends CGridView

{

public &#036;cssFile = 'yourStyle.css';

}

?>[/CODE]

Hi Coksnuss,

Can you elaborate me more, means how can i call this $cssFile variable in zii grid.

What exactly do you need to know?

From what I have understood, you’ve changed the source code @framework/zii/widgets/grid/CGridView.php and searching for a way to do this changes without changing the framework files. Am I correct with that?

If I am correct: What exactly did you changed?

No, in asset folder there are some files for zii grid view, i changed that but when i upload the same project on different server in asset folder new folder is generate for zii.

I just want a way by that if i fixed the layout of grid view then i dont need to change it on different servers.

Thanks

Ah ok, I see. Well then you can use my provided solution without any problems.

The approach in detail (assuming default paths)

protected/config/main.php


return array(

[...]

'import' => array('application.components.*'),

[...]



protected/componentns/GridView.php


Yii::import('zii.widgets.grid.CGridView');

class GridView extends CGridView

{

    public function init()

    {

        $this->cssFile = Yii::app()->baseUrl . '/css/gridview.css';

        parent::init();

    }

}

css/gridview.css




Just copy&paste the content of your modified style.css in here.



Now simply search and replace all calls of


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

to


$this->widget('GridView', array(...));

Done.

Thanks :)

Hi Coksnuss

One more help, in zii grid, when i enter something in filter textboxes, loading image is show but it does not filter the result, what is the issue ?

Thanks in advanced

Hi

As it looks like this was not stated explicitally:

  1. You should not manually change any file under the ‘assets’ folder. The files there are copied/generated. At best you should make sure that your setup is still working after deleting the entire assets contents!

  2. You can specify your own ‘css’ file as indicated above by specifying this as an option to the gridview, or you can create a CSS file that you also load in which you create more specific rules. One technique I use is to add ‘body’ in tront of the rule - the body is always available and it makes the rule more specific.

So:

".gridview .abc { color: green; }" would become "body .gridview abc {color: red; }" if you prefer to use read for ".gridview .abc" rather than the default green.

Hi Coksnuss

Can you tell me also how can i change button path of zii grid view

Hi,

please refer to the API Documentation:

http://www.yiiframework.com/doc/api/1.1/CButtonColumn#viewButtonUrl-detail

http://www.yiiframework.com/doc/api/1.1/CButtonColumn#updateButtonUrl-detail

http://www.yiiframework.com/doc/api/1.1/CButtonColumn#deleteButtonUrl-detail

for example:




array(

 'class' => 'CButtonColumn',

 'viewButtonUrl' => 'Yii::app()->controller->createUrl("yourViewAction", array("parameter1" => "value1"))',

)