Welcome Guest, Not a member yet? Register   Sign In
Auto routing and/or defining routes
#1

Hello community
I'm struggling with routing in my new application. I'm coming from CI3 and am used the auto routing stuff. Now I learned about defining routes for the application. But I can't find the right solution that works for my purposes.
What I like to achieve is to route a handful of URIs to some specific controllers, some of them organised in a sub directory. Then I have all the other URIs which I'd like to route to a single controller to get the dynamic page content together.
Controllers' directory:
-- BaseController.php
-- Site.php
-- Login.php
-- Apps
-- -- Home.php
-- -- App1.php
-- -- App2.php
-- -- …
The Site controller should get every request from URIs not beginning with login or apps/appX. So I defined a route like this:
PHP Code:
$routes->get('/''Site::index');
$routes->get('/login''Login::index');
$routes->get('/(:segment)''Site::index');
$routes->get('/(:segment)/(:any)''Site::page'); 

What happens now is that all the dynamic URIs are routed to Site::index and Site::page. So far so good. The Login page also works fine. For the AppX controllers I wanted to use auto routing, because there are a lot of controllers inside the App sub directory. So I activated auto routing as mentioned in the user guide.
But I can't get it working. If I call /apps/app1 I get routed to Site::page. I guess the problem is that CI is working the defined routes before looking for a specific controller file for auto routing to it.
My questions:
Is it generally not possible to define routes when auto routing is enabled?
How can I achieve what I'm trying to?
Thanks for your help!
Reply


Messages In This Thread
Auto routing and/or defining routes - by bastian - 09-23-2024, 11:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB