Organize Models directory into subdirectories

Hi, I would like to know if there is a way to organize models inside subdirs in "model" dir. I mean a structure like this:







and so on…

if it is, how to call model inside a subdir?

Thanks for all


add your directory alias to the import array in conig.

but alias works with one directory, or not?

I mean I need to put models inside several directories (models/group1 models/group2 and so on…), not all in one.

You should add all subdirectories. But I don’t think you need all of them at once. If your controlller use group1 and group5 models, then better use Yii::import(‘protected.models.group1’) [and group5] in it’s init method.

Thanks andy_s it works perfectly :)

Hey Guys, I’m having problems getting this to work. I have the following in my controller:

  class UsersTestHarnessController extends Controller



    public function init()





When my controller action is called I get:

Alias "protected.models.Users" is invalid. Make sure it points to an existing directory or file.

I have tried upper/lower case, adding an asterisk…

Replace protected with application.

I replaced my import with:


It works! Thank you very much Mike!