Skip to content
Advertisement

php mvc url pattern which takes three arguments

I’m new to MVC. what I’ve learned from a few articles and some videos is that the general form of URL in MVC structure is as controller/action. but I’ve come across some URLs like this:

www.exmaple.com/users/login/confirm

which takes three parameters(users, login, confirm). I don’t understand which one is the controller, which one is the action, and what the third parameter is.

On the same website, there is also such URL:

www.exmaple.com/users/login-register

so, how does it know when to treat the second parameter as the action and when as the controller?

Advertisement

Answer

It is not a one rule for all to map your URLs as controller/action. It is just a common practice most people use.

For example the one you mentioned in question, users/login/confirm, is literally used for confirming an event related to the login. Why it is not users/confirm? Well the reason might be that the route usersconfirm is used for another operation like registration confirmation or confirming user addition by admin or etc. So in the application there was multiple confirmation logic so the programmer just segregated them with another parameter (login here).

The best way to understand what is going on behind the scenes is just to read the code or documentation of that code.

Note: It is important to understand the value of clean URL here, since if it was clean from the start, you wouldn’t have had these issues with understanding the logic.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement