CodeIgniter Forums
Understanding routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Understanding routes (/thread-75171.html)



Understanding routes - bystefu - 01-04-2020

Hello, i'm new in CI and i just started my app.My question is about routes, if i have :

PHP Code:
$route['something/(:any)'] = 'Login/test/$1'

And if i request 'something' without anything, i must to make another route like this : $route['something'] = 'Login/test'; and finally to look like this:


PHP Code:
$route['something'] = 'Login/test/$1';

$route['something/(:any)'] = 'Login/test/$1'


[font=Monaco, Consolas, Courier, monospace]Or is another way to make this?[/font]

[font=Monaco, Consolas, Courier, monospace]My controller is:[/font]

PHP Code:
class Login extends CI_Controller{

    public function index(){
        $this->load->view('login_view');
    }
public function 
test(string $ceva){

        if(isset($ceva)){
            echo "avem setat {$ceva} <br />";
        }
        echo "sunt si aici";
    }




RE: Understanding routes - littlej - 01-06-2020

Hello,

I think that this is a CI3 question posted in the CI4 section :-)

If you are talking about CI4, you can use " $routes->resource('something'); ". It will create all routes for you and solve your problem: https://codeigniter4.github.io/userguide/incoming/restful.html

Anyway, the "app/Config/Routes.php" file says:
// We get a performance increase by specifying the default
// route since we don't have to scan directories.

So I prefer to define all routes manually. I don't know if this is the right reasoning to have though :-)