Nested controllers?

Hello,

I just recently started using Yii and must say that it's fantastic, but… What am I wondering here is if it's possible to use some kind of nested controllers. As it is now, I have a UserController with methods like actionViewProfile, actionEditProfile and actionViewMail. I think would look better and be more convenient if I could have this controller structure:

controllers/

  UserController.php

  user/

    ProfileController.php

    MailController.php

With URLs like user/profile/edit instead of user/editProfile. I realise that you probably could use patterns to achieve these URLs, but then I'd have to do it for almost all controllers, since this is the way I think.

So, is this possible? Or should I use some entirely different method? If there's no relatively easy way to do it, I think I'll just create a ProfileController (in the root of the controllers directory) and hope I won't have to create any controllers with similar names or exactly the same one.

Yes, this is possible. See http://www.yiiframew…ontroller#route

The URL for your example would be: index.php?r=user.profile/editProfile

Thank you! That’s exactly what I was looking for. I must say I’m impressed with how quickly you answered my question :o

Good framework. Good work!

But URLs like - user.profile/edit looks not good.

user/profile/edit will be very nice.

It is actually possible to support format user/profile/edit (by overriding CUrlManager), but this is at the cost of performance degradation, because the URL manager needs to check if there is "user" directory and a "ProfileController.php".

Yeah, I don't really recommend doing that. Prior to using Yii I was trying to create  my own framework and implemented the behaviour mezoni is describing. Not only is it a pain in the butt to implement in what I'd call a clean way, if you've taken a liking to nested controllers (like I have) there'll be a whole lot of file_exists:ing and whatnot. I don't think it's worth it. Besides, I happen to think that "user.profile" looks just fine. 'cuz it does. O ho ho.

I'm using latest build (Yii 1.0.3) and there are problems with it. When I call

http://site/myStyle/…mendations.html

having the rule in the UrlManager:

'/myStyle/recommendations'=>'user.alternative/list',

And controller in protected/controllers/user/AlternativeController.php Abd action actionList in that controller, it outputs:

Page Not Found

Unable to resolve the request "user.alternative/list".

What's the problem?

It was changed to user/alternative/list.

Please read UPGRADE file in the release.

Didn't take a look at UPGRADE yet, but when I cahnge to user/alternative/list it tells me:

Page Not Found

The system is unable to find the requested action "alternative".

I should read it, yeah? :)

Do you have a UserController?

yes. I should not have it in order to use this feature?

That's right. When Yii sees user in the route, it first attempts to look for UserController. If not found, it will look for a directory named 'user' and search below.

OK, thanks.

Um… one more problem - views. I thought they should be in the same folder controller lies:

/controllers/userActions/AlternativeController.php

/controllers/userActions/views/alternatives.php

But it tells it can't find the view file…

It still uses the normal controller view path, i.e., /views/controllerID/viewName.php

Strange, but it doesn't see it there either. Or maybe I'm too sleepy now and can't see some typos. OK, thanks for your help. I'll read the UPGRADE file tomorrow and sort that out.