I want auto routing in codeignitor 4 but don't know how to do it.
As said in the Routes.php file, I have set the "setAutoRoute" to true and also set $autoRoutesImproved to true in "app/Config/Feature.php" but always show 404 error.
app/Config/Routes.php
$routes->setAutoRoute(true);
app/Config/Feature.php
public bool $autoRoutesImproved = true;
I want URL to be like http://localhost/codeigniter4/pages "pages" is my new controller.
http://localhost/codeigniter4/pages
The route above would mean:
codeigniter4
- (URI segment 1) - Is the Controller name.pages
- (URI segment 2) - Is the method name.You got it wrong because you were expecting "pages" to be the controller's name, which isn't the case.
When no defined route is found that matches the URI, the system will attempt to match that URI against the controllers and methods when Auto Routing is enabled.
The segments in the URL, in following with the Model-View-Controller approach, usually represent:
example.com/class/method/ID
The first segment represents the controller class that should be invoked.
The second segment represents the class method that should be called.
The third, and any additional segments, represent the ID and any variables that will be passed to the controller.