Ambiguous Controller

Hello, I’m using Yii 1.0.11.

I’m curious about how make the correct development, I have the next URL “http://www.mysite.com/user/name” (the word “name” can be “jonh”, “rachel”, …). The word name will be registered by the user logged in, if a guest visit “http://www.mysite.com/user/jonh” then he will be directed to jonh’s site…

But if I have an action named "create" in the UserController and the user logged in try to register the next URL "http://www.mysite.com/user/create" it will be a big problem.

My question is, how to make it to work fine and safe?

Remembering that UserController is used to register a new User and give to this User one shortcut to "his site".

I think the best way to do this would be not to have any actions in your user controller at all. Then override the missingAction() method. In your override, redirect or handle the user request.

Then I need one model, two controllers and change my main(config) to redirect /user/myMissingAction to the second controller with a missingAction treatment?

Thanks and Merry Christmas

You don’t actually have to have the url contain ‘missingAction’. Your user controller would have a function called missingAction what happens is when a route points at your controller and they app can’t find the action in the controller it then calls the missingAction function, from there you can do what you want.

See this post for an example of how I used the missing action function.

Some of what you need to do is just have a list of user names they just can’t use your original way would work but you’d need to prevent your users from registering user names that are action names. If you go with the 2 controllers, one controller could handle the register/log in and other user functions and you could have the second controller handle then accessing their user page.

I undertand, when I say /user/myMissingAction I’m refering to /broker/jonh for example, and jonh will be my “missingAction” in this case. I read your post before post this, then… ultimately I code it:

  • 2 models equal (I don’t know how to do with one because each one will be used by one controller)

  • 2 controllers -> one to user (with methods for CRUD), another to broker (only with missingAction method for now)

It’s working, but I don’t know why I have to have two models for two controllers when broker and user are equals and in database it referenced only by broker table?

Sorry for my bad English.

Thinking about it… how I do to have http://www.mysite.com.br/admin/broker/list in place of http://www.mysite.com.br/broker/list?