![]() |
Myth/Auth - Routing problem - 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: Myth/Auth - Routing problem (/showthread.php?tid=76073) Pages:
1
2
|
Myth/Auth - Routing problem - BilltheCat - 04-12-2020 I can't see what I'm doing wrong here, as everything I've read seems to say this SHOULD work. I'm filtering routes to the User controller, and the controller index method does NOT work, while the profile method works fine. I'm lost... ![]() Very basic implementation here: App\Controllers\User.php PHP Code: <?php namespace App\Controllers; App\Config\Routes.php PHP Code: //Restricted to logged in users RE: Myth/Auth - Routing problem - includebeer - 04-12-2020 The first route would give domain.com/user/user Is this the URL your are typing? What doesn’t work? Do you get a 404 or something else? Maybe this would make more sense? PHP Code: $routes->group('user', ['filter' => 'role:Users'], function($routes) { RE: Myth/Auth - Routing problem - BilltheCat - 04-12-2020 I have the URLs as domain.com/user/index And domain.com/user/profile Doesn'ft your method with '/' point the routing to the home controller? The problem is that the filter doesn't prevent guest users from visiting the User controller index. RE: Myth/Auth - Routing problem - BilltheCat - 04-13-2020 Well, it works... I'm not sure why yet, but I guess I have some documentation to read up on. Thanks for your help, @includebeer RE: Myth/Auth - Routing problem - includebeer - 04-13-2020 No that’s not the URL these routes will point to because you are using a group. The group function is there to not having to repeat the same things for all route. PHP Code: //Restricted to logged in users ...is the same as: PHP Code: $routes->get('user/user', 'User::index', ['filter' => 'role:Users']); // Does NOT work RE: Myth/Auth - Routing problem - BilltheCat - 04-13-2020 Ahha, thanks again! "The group name becomes a segment that appears prior to the routes defined inside of the group." That cleared it up for me. ![]() RE: Myth/Auth - Routing problem - Nome - 04-13-2020 My problem is of a similar nature, so I did not begin to create a new topic. I still use modular code, it is very convenient. But now I am faced with an incomprehensible problem. I have a user module, in its config there is a route that consists of a simple group: PHP Code: $routes->group('user', ['namespace' => 'Modules\User\Controllers'], function($routes) After my form(method="POST") located at the address, site/user/, sends data to the address site/user/add, a message appears with the following text: Code: 404 - File Not Found It turns out that the get method works and the post does not ... Tell me what is my mistake? There is almost nothing in the APP\Co..\Routes.php except : $routes->setTranslateURIDashes(false); $routes->set404Override(); $routes->setAutoRoute(true); Thanks! RE: Myth/Auth - Routing problem - includebeer - 04-13-2020 I’m not sure if this is causing this, but you should set auto route to false if you are defining your own route. It is looking for User:add instead of User::createUser, so I guess it’s the auto routing that gets in the way. PHP Code: $routes->setAutoRoute(false); RE: Myth/Auth - Routing problem - Nome - 04-13-2020 (04-13-2020, 06:39 AM)includebeer Wrote: I’m not sure if this is causing this, but you should set auto route to false if you are defining your own route. Apparently not, because it changed to a value: Code: Can't find a route for 'user/add'. Environment: development says me: Code: DEFINED ROUTES In my : modules\User\Controllers\User.php PHP Code: public function index() { RE: Myth/Auth - Routing problem - includebeer - 04-13-2020 DId you add your module’s namespace in the Autoload file? |