Relative Path in main.php

Hi,

how can i get the relative path(basePath) in config file "main.php" ?

The problem: i need configure the “widgetFactory” themeurl. I can’t use /css/jqueryui because the correct path is /boletim/css/jqueryui(is not in root directory, but this can change in future).

Not is possible use Yii::app()->getXXXXX because i think the application is not ready.

Thanks.

Like mdomba says here, declare $basePath outside the config array (and refer to it as needed)




$basePath' = dirname(__FILE__).DS.'..';


return array(

  'basePath'=>$basePath,

  ...

  'import'=>array(

    ...

  ),

  'modules'=>array(

    ...

  ),

  'components'=>array(

    ...

  ),

  ...

);



/Tommy

Thanks Tri,

The format ‘.\…\…\css\jqueryui’ it’s not work. I need the relative path like this ‘/boletim/css/jqueryui’ for use in “themeurl” .

Thank you.

Something like this?




$basePath' = DS.'boletim';


return array(

  'basePath'=>$basePath.DS.'protected',

  ...

  'import'=>array(

    ...

  ),

  'modules'=>array(

    ...

  ),

  'components'=>array(

    ...

  ),

  ...

);



(I think you’ll get the idea.)

Edit: This will not work. Sorry for this bad suggestion. I mixed it up with base url. An environment dependent absolute path is needed.

/Tommy

Thanks.

I thinking in something automatic.

If the client change the server or the directory where the site is saved the client will need change the configuration file.

You can consider changing the widgetFactory properties at a later stage.

E.g in the Gii-generated base controller




  public function init()

  {

    // show the widgetFactory object

    echo '<pre>'; print_r(Yii::app()->widgetFactory); echo '</pre>'; 

  }



Edit:

I totally forgot about other ways to override factory properties like skins and createWidget calls.

(Really have to do some Yii programming soon.)

Edit 2:

Read your first post again. You are probably looking for a url relative to the application (assuming that with boletim you mean the application directory)




Yii::app()->getBaseUrl().'/css/jqueryui';



/Tommy

It’s not easy to find a good solution.

On PHP 5.3.0+ it’s possible to do this (but has to be called so CWidgetFactory will need modification)


'themeUrl' => function() { return Yii::app()->getBaseUrl().'/css/jqueryui'; },

Here’s an alternative

This thread by Eddie Parker introduces a solution for selecting jui themes in a common place for all jui widgets. I think it could be enhanced with the possibility to select themeUrl and others.

Then this could be specified in config to be evaluated on instantiation of widgets




'modules'=>array(

  'config-only' => array(

    'jui' => array(

      //...

      'themeUrl' => function() { return Yii::app()->getBaseUrl().'/css/jqueryui'; },

    ),

  ),

),



Edit: since ‘jui’ actually isn’t a Yii module (follow the above link), I added ‘config-only’ (neither one will be instantiated)

/Tommy

Thanks Tri for your help.

I will try.