When I create a controller in CodeIgniter, for example “login.php”. I create a public function “index” in it, and load a view “login_form” in the function, the CodeIgniter generates the url localhost/test/login.
Now, If i create another function “register” in the same Controller, the url will be localhost/test/login/register, but I want to create url like localhost/test/register. Do I need to create a new controller register and make the index function in that, or same URL can be generated by adding function in login controller. What is the ‘usual’ way to do it?
Thanks.
As mentioned you can (and most likely should) use a route for this:
This is basically saying: If
/registeris requested, give them/test/register.Note that
/test/registeris still valid. If you want to disable it for some reason, you can do this:…but in general you won’t need to.
Note that use of routes does not magically rewrite your links or anything, it just routes the request somewhere else when it is made.
Remapping is quite cool, but what you’re asking is definitely a job for a route. Read the user guide carefully, there’s a lot you can do with them.