How to use models in a sub folder in yii1.x

Yii

Posted on 28 May 16 by Vickey
  616



Some times we have two different types of models in our projects for example we have many models and some have prefis 'student' ( student_users ) and some have 'teacher' (teacher_users). So if you want to put these types of models in a different directory you can create a two subdirectory under your model directory and put your models here

 

models

            teacher

            student

Now you need to do some changes in your main.php file under 'protected/config'.  Open main.php file and seacrh  'import'=>'. you will see something like this

'import'=>array(

	'application.models.*',
	'application.components.*',
	'application.widgets.Notification',
	//'ext.yii-mail.YiiMailMessage'
),

change it to

'import'=>array(

	'application.models.student.*',
	'application.models.teacher.*'

	'application.components.*',
	'application.widgets.Notification',
	//'ext.yii-mail.YiiMailMessage'
),

and now can load your models from different locations


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com