July 11, 2011, 4:57pm
Recently found interesting case on
StackOverflow.com. Please follow this link..
I’ve created new application and tried to reproduce the same situation and it didn’t work for me too.
Controllers structure (copied directly from SO):
When I tried to access bookmarks/categories, an exception has been thrown (unable to find an action called categories in BookmarksController). I haven’t found a word about such problems in docs.
How do you usually solve such problems?
July 11, 2011, 5:25pm
I’m not sure it’s possible because Yii searches for controllers in the CWebApplication.controllerPath. Look at this method:
Having subdirectories in the controllers directory may be ambiguous, because when accessing "user/profile/update" it is hard to say, is "user" a module or a directory under controller path.
Also I think controllerMap is not what you need. So the only possible option I see is to create a module "bookmarks".
July 11, 2011, 6:32pm
Thanks for your answer.
So, how do you usually resolve such issues with Yii?
July 11, 2011, 6:56pm
Previously I was creating modules for each site section. But in the last project I put all controllers (20 or more) into the one directory, and I don’t have any problems with it, since all controllers have unique names (same as models names but with “Controller” in the end).
If you want a url "bookmarks/categories" for controller CategoryController, just add a url rule in the application config:
July 11, 2011, 7:09pm
If the concern is about separating code into smaller chunks, you could write actions by extending CAction instead of writing actionXyz methods within the controller. These could be easily structured in subdirectories.
BookmarkController then whould mainly delegate:
class BookmarkController extends Controller
public function actions()
'create' => 'path.to.CreateBookmarkAction',
'list' => 'path.to.ListBookmarksAction',
'createCategory' => 'path.to.CreateBookmarkCategoryAction',
'listCategories' => 'path.to.ListBookmarkCategoriesAction',