Basic Question on CodeIgniter URL

When I create a controller in CodeIgniter, for example, "login.php". I create a public index function in it and load the login_form function into the function, CodeIgniter generates a url localhost/test/login.

Now, if I create another function "register" in the same controller, url will be localhost/test/login/register, but I want to create url as localhost/test/register. Do I need to create a new controller register and make an index function in it, or can the same URL be generated by adding a function to the input controller. What is the “normal” way to do this? Thank.

+3
source share
3 answers

As already mentioned, you can (and most likely should) use:

// config/routes.php
$route['register'] = 'test/register';

: /register, /test/register.

, /test/register . - , :

$route['test/register'] = FALSE; // Or map to your 404 page

... .

, - , - , .

Remapping , , , - . , .

+5

I would suggest reading this guide on how to extend your controller (in this case register) using login validation. This will allow you to protect the code in the function of indexyour controller register. And in any other controllers that you can add. I think that in your approach, you now run the risk of having one redundant controller logininstead of having several smaller controllers with a slightly larger structure and overview.

+1
source

All Articles