Configuration of cssFile attributes with widgetFactory

Hey everybody.

i’m trying to configure the CLinkPager and the CGridView widgets through the WidgetFactory. Everything works fine, but wasn’t able to figure out how to get base URL path to correctly set the cssFile attributes.




'widgetFactory'=>array(

  'widgets'=>array(

    'CLinkPager'=>array(

      'maxButtonCount'=>5,

      'cssFile' => 'application.css.pager.css',

    ),

    'CGridView'=>array(

      'cssFile' => 'application.css.css.style-gridview.css',

    ),

  ),

),



Also tried Yii::getPathOfAlias() and Yii::app()->baseUrl. Nothing seems to work.

Any hints on how to get the base URL are highly appreciated.

cheers

Simon

Try




'widgetFactory'=>array(

  'widgets'=>array(

    'CLinkPager'=>array(

      'maxButtonCount'=>5,

      'cssFile' => Yii::app()->baseUrl.'/css/pager.css',

    ),

    'CGridView'=>array(

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

    ),

  ),

),



If your css are in basePath/css (NOT IN PROTECTED) it will work.

If they are under protected you have to publis in assets, but is not needed to protect the css

Already tried that and got the following error message:

Unfortunetly the getBaseUrl() methode is only available after the application is initialized and therefore not accessible in the config. As this method is only utilizing the $_SERVER var, it might be a good idea to make it available as a static method in the YiiBase helper class?!

So far the only solution to get the base path i found is this:




rtrim(dirname($_SERVER['SCRIPT_NAME']),'\\/')



It’s part of the getBaseUrl() method code. I don’t know if this works in every environment, but it does work with apache.

If somebody found a better solution i would be glad to see it.

cheers

Simon

When I try set the cssfile or any other property in config file, it shows an error that ‘Property “CWebApplication.widgetFactory” is read only.’ . For example, following code shows the error.

‘widgetFactory’=>array(

‘widgets’=>array(

'CLinkPager'=>array(


  'maxButtonCount'=>5,


),


'CGridView'=>array(


  'cssFile' => '/css/style-gridview.css',


),

),

),

I am using 1.1.5