Module Include Path

I’ve only recently started using modules in Yii and I’m having a bit of trouble with the include paths.

I have a super controller that I use in my base application to subclass all my other controllers. It contains a few routines and variables I use in all my controllers.

SuperController.php




class SuperController extends CController

{

	public $superVariable;


	public function __construct($id,$module=null)

	{

		parent::__construct($id,$module);

		$this->superVariable = "Super Value";

	}


	public function superFunction()

	{

		$this->superVariable = "Super Function";

	}



In my module I want to extend that behavior so I’ve added a module super controller that all of my module controllers will subclass.

ModuleSuperController.php




Yii::import('application.controllers.SuperController');

class ModuleSuperController extends SuperController

{

	public function __construct($id,$module=null)

	{

		parent::__construct($id,$module);

		$this->superVariable = "Module Super Value";

	}


	public function superFunction()

	{

		$this->superVariable = "Module Super Function";

	}



I can’t seem to figure out how to set up autoloading properly. To extend my ModuleSuperController in my module classes I have to manually import it (which is a bit of a nuisance).




Yii::import('application.modules.module.controllers.ModuleSuperController');

class ModuleController extends ModuleSuperController



I can resolve this by adding my module controllers directory to the import array in the main config, but I’d rather not have to add entries for the controller, model, and whatever else for every module I create.




'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.modules.module.controllers.*',

	), 



Is there a better way to do this?

I would do the import in the modules init method:





class MyModule extends CWebModule

{

   ....


  public function init()

  {

     parent::init();


     $this->setImport(array(

                           'application.controllers.SuperController',

                           'mymodule.controllers.*', 

                           'mymodule.components.*',  

                           'mymodule.models.*', 

                            ....

                            

	             ));

  }  

   ...


}




Beautiful! +1

Thanks,

Jason