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:

model/group1/model1.php

model/group1/model2.php

model/group1/model3.php

model/group2/model4.php

model/group2/model5.php

model/group3/model6.php

and so on…

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

Thanks for all

Danilo

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()

    {

      Yii::import("protected.models.Users");

    }

    ...



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:




Yii::import("application.models.Users.*");



It works! Thank you very much Mike!