Putting controller configuration in the configuration file

Does anyone know how to place configuration stuff for say a controller in the config file. I have this controller i’d like to set paths for in in the configuration file for it to search.

i tried


'components'=>array(

  'AppController'=>array(

  'appPaths'=array('<path>')

))

and have a public $appPaths in the controller.

when the controller runs and i dump the array to the output there isn’t anything.

This isn’t possible. “components” is for subclasses of CComponent only. Why not just do:


class MyController extends CController

{


  public $appPaths = array();


}

If you want to store special values in the config you can use the params array.

You can put data in ‘params’ element of configuration file. not ‘components’ element.




'params'=>array(

		'myData'=>'This is my configuration data',

	),



And access it in your controller.




Yii::app()->params['myData']



already done this. Also CController is a subclass of CComponent when you drill down. What I wanted to know was what I’m missing in my controller as I really couldt see anything special in other components that we can set stuff from there.

From CConfiguration.php…




/**

  * Loads configuration data from a file and merges it with the existing configuration.

  *

  * A config file must be a PHP script returning a configuration array (like the following)

  * <pre>

  * return array

  * (

  *     'name'=>'My Application',

  *     'defaultController'=>'index',

  * );

  * </pre>

  *

  * @param string configuration file path (if using relative path, be aware of what is the current path)

  * @see mergeWith

  */

public function loadFromFile($configFile)

{

  $data=require($configFile);

  if($this->getCount()>0)

   $this->mergeWith($data);

  else

   $this->copyFrom($data);

} 

I would imagine that if your controller is a module controller, you probably would need to add the path alias for the controller’s config/ folder to your <ModuleName>Module.php file so Yii can find it.

I figured out how to do it though i moved the variable from the controller to my web application class.

The configuration then became:




array(

   'appPaths'=>array(<path>)

)

I can then access it by doing




Yii::app()->appPaths;



the params array is nice but sometimes it’s nicer to not have to type the access statment for the params.

I’m also working with a multi file configuration and some configurations are set in the common framework and some are set by the actual application and the common framework uses the settings that are set by the app.