Naming questions


As we all here, I’m trying to build an application upon Yii.

I stumpled upon a few questions doing this:


[*]Naming classes and subfolders. I noticed that if my folder structure looks for example like this:

- UserController.php

- SomeotherController.php

- user/

- - user/profileController.php

- - user/etcetcController.php

It don’t work well. I understand why, because the system don’t know wheter to look in the controller ‘user’ for some action called ‘profile’ or to look in the controller user/profile for the ‘index’ action.

My question is, how to solve this?

I thought of two solutions but I don’t know which is the best:

  • Renaming my folder to for example, user_sub

so I get this:

- UserController.php

- SomeotherController.php

- user_sub/

- - user_sub/profileController.php

- - user_sub/etcetcController.php

  • Or placing my UserController inside the user folder, so I get this:

- SomeotherController.php

- user/

- - user/userController.php

- - user/profileController.php

- - user/etcetcController.php

and call it by user/user/someAction

Which one is the best? Or is there any other solution?

[*]Using a method of another class.

At first, I tried to use


The desadvantage was the impossibility to use parameters in this method, so I had to use flashvar’s, which is quite ugly to do in this situation (imo). So I thought to import the whole class and use the method I need. One problem: how do I import a class in a subfolder? I tried a couple of things, but none of them worked. Or am I missing something and are there other ways to do this?


I understand that you are trying to modify your controllers folder structure and I wonder why would you do that? If you follow MVC recommendations ( you will realize that controllers are very thin and the actual folder structure is quite good.

In order to do what you aim to do, you will have to tell CUrlManager what you want ( Nevertheless, I recommend you not to do so and use a different approach.

You should not create folders in controllers, as this directory content is autoloaded by yii.

If you path like:

you can create a module user, check the guide about it.

This allows you to use many action for each controller.

Thanks guys, I got it!