CodeIgniter Forums
Custom Routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Custom Routes (/showthread.php?tid=75603)



Custom Routes - lucasrohers - 02-25-2020

Hello friends, CI4 was launched and it is simply, excellent. I am updating my projects, but I have some difficulty in the routes.
I have a website with a BLOG system and user login. Everything works fine, however, I can't do the correct routing for the news to access only with / url-NOTICIA
I managed to make it work as follows:
$routes->get('/', 'Home::index');
$routes->add('(:any)', 'Home::post/$1');


However, all my other controllers that are after domain/, for example domain/login or domain/ settings are automatically redirected to the home page. I tried to add:
$routes->get('settings', 'Settings::index');


And then the page accessed, but he has no access to the other methods inside the controller. Besides that, I tried to add a route for the methods, and it didn't work.

* I followed the documentation .. but .. Where am I going wrong?


RE: Custom Routes - MGatner - 03-01-2020

(:any) catches literally anything, so you've essentially said "anything that is not example.com/ goes to Home::post/$1". You will either need to loosen up your rule or add some more explicit routes first.