Yii Framework Forum

Load a module's model from the main app controller


(Graffiti Nerd) #1

I would like to load/use a model(Importedbooks) which is in module(booksImported) from main app controller(SiteController),

main.php




       'import'=>array(

    'application.models.*',

    'application.components.*',

            'application.modules.booksCategory.models.*', 

            'application.modules.booksImported.models.*' 

         ),

    'modules'=>array('booksImported')

 

In my SiteController function i tried this…which only gives me the Module name.




 Yii::app()->getModule('Importedbooks')



I also tried




       Yii::setPathOfAlias('booksImported','../modules/booksImported/models');


        Yii::import('booksImported.models.Importedbooks',true);  // this will include the class DesiredModel immediately


        $model = Yii::createComponent('Importedbooks');


        print_r($model);



which gives an error




Alias "booksImported.models.Importedbooks" is invalid. Make sure it points to an existing PHP file and the file is readable.



I am really battling with this. Is what i am tying to do possible?, if it is please help.