Yii 1.1.3 Widget configuration for CButtonColumn

Great work on 1.1.3!

Now, I was trying to use the new default config options for the widget factory. I’ve been replacing the default delete link image in my CButtonColumns manually so far, and decided to try specifying that option in my config using the new widget factory default configuration.

I’ve got this in my /config/main.php, under components:




'widgetFactory'=>array(

      'widgets'=>array(

            'CButtonColumn'=>array(

                  'deleteButtonOptions'=>array(

                        'class'=>'useTooltip','height'=>'25','width'=>'25'),

                  'deleteButtonImageUrl'=>

                        Yii::app()->request->baseUrl.'/images/i_logout.png',

             ),

       ),

),



and - nothing. Is there another way I should be doing this?

Yii::app()->request is most likely not initialized at the time, the config file main.php is read.

Ah, good point - thanks for the response. However, I tried switching it to this:

\




'widgetFactory'=>array(

     'widgets'=>array(

          'CButtonColumn'=>array(

               'deleteButtonOptions'=>

                     array('class'=>'useTooltip','height'=>'25','width'=>'25'),

               'deleteButtonImageUrl'=>'application.images.i_logout.png',

           ),

     ),

),



… and still nothing. Also, the options part isn’t being rendered, so it appears the problem is bigger than specifying the path.

I think the widget should be CGridview here, thus try something like this




'widgetFactory'=>array(

  'widgets'=>array(

    'CGridView'=>array(

      'columns'=>array(

        array(

          'class'=>'CButtonColumn'=>array(

            'deleteButtonOptions'=>

                     array('class'=>'useTooltip','height'=>'25','width'=>'25'),

            'deleteButtonImageUrl'=>'application.images.i_logout.png',

          ),

        ),

      ),

    ),

  ),

),



(not tested)

/Tommy

This is because CGridColumn is not a widget. So widget factory won’t help you.

Well, that explains it then - thanks for the replies, everybody.

So, there is no easy way to set CButtonColumn images for the whole site, without modifying the framework assets or sub-classing CButtonColumn?

Your question implies, that subclassing CButtonColumn is not easy. I would not necessarily agree to that:




class MyButtonColumn extends CButtonColumn 

{

  public function init()

  {

    $this->viewButtonImageUrl=Yii::app()->request->baseUrl.'/img/myViewButtonImage.gif';

    return parent::init();

  }

}

I ended up doing the same. Subclassing per se is not a problem, I just have to change the CButtonColumn to MyButtonColumn in many places => update many files on the server, but it works, so it is OK :)

Thanks for you post and answers I had the same questioning and it helped me a lot.

But it leads to a general question about extending existing objects. In this case where would you put the file containing the MyButtonColumn extended object : protected/components or protected/extension ? I must admit this is not always very clear to me. I guess both would do but what is the best practice and why ?

Thanks in advance for you answer.

There’s no standard for this. For a start just put it into /components. When you find, that this folder gets too crowded, think about how you can reorganize the files. This really depends on your project and how many custom classes you need. You could for example create “/components/widgets” for all your widgets. Just remember that you must import all your custom folders explicitely in your config/main.php.

Yes it is. This seems to be the only "polite" way.

When I used these techniques, injected a replacement for framework or extension classes.

Take a look how (third code block of this post: http://www.yiiframework.com/forum/index.php/topic/37484-how-to-force-inclusion-by-config-entry/page__p__181302#entry181302)

Have anyone tried overwriting "baseScriptUrl" property for CGridView when configuring widgetFactory entries?

THIS HAS SOLVED THE PROBLEM FOR ME




	'CGridView'=>array(

		'htmlOptions'=>array(	'cellspacing'=>'0','cellpadding'=>'0'),

					'itemsCssClass'=>'item-class',

					'pagerCssClass'=>'pager-class',

					'baseScriptUrl'=>'themes/shadow_dancer/assets/gridview'

                		    ),

		...