Bug in routes with path in controller |
Hi, Routes with pass parameters such as the following:
$routes->get('/movie/test/(:any)', 'dashboard/MovieController::test/$1'); They only work if the controller (for example MovieController) is in the root: $routes->get('/movie/test/(:any)', 'MovieController::test/$1'); In the first case ($routes->get('/movie/test/(:any)', 'dashboard/MovieController::test/$1');) the error it gives is the following 404 - File Not Found Controller or its method is not found: \App\Controllers\dashboard::index It does not recognize the controller according to the error it throws; But if I remove the dasboard from the configuration like: $routes->add('movie/test/(:any)', 'MovieController::test/$1'); its working
You can use only
$routes->add('journals', 'App\Blogs'); if dashboard is files and it have controller you must use \ .Its run default index function. $routes->add('blog/joe', 'Blogs::users'); if dashboard is controller you must use scope + function you can see https://codeigniter4.github.io/userguide...uting.html Sercan YANBULOGLU
SEO links REDACTED, per forum policy
dashboard is a folder:
-Controllers (folder) -dashboard (folder) -MovieController (class PHP - controller) I want to put the controllers of the administrative module inside a folder (dashboard) and in another folder my Rest Api (rest folder) thank you!
(11-25-2019, 04:41 AM)acy29 Wrote: dashboard is a folder: Dashboard folder must be with first upper case letter D. Try that, cause at least that was the case few month ago
Am also experiencing the same issue with routes with parameters
PHP Code: $routes->group('usergroups', ['filter' => 'ajax'], function($routes){ This route is not working. Am getting 404 error. Controller method is not found: index I have controller in: App/Controllers/Backend/Users.php PHP Code: <?php how can i fix this issue? (11-30-2019, 05:41 AM)midhunlalkc Wrote: Am also experiencing the same issue with routes with parameters It is because codeigniter is expecting all of your controllers to be in one folder, App/Controllers. If you try to reference it out of that, then it says it can't find it and throws a 404 error. The solution is really simple, just tell it where the new namespace is: $routes->add('(:num)/edit', 'Users::editGroup/$1', ['as' => 'edit_group', 'namespace' => 'App\Controllers\Backend']); https://codeigniter4.github.io/userguide/incoming/routing.html#assigning-namespace Hope that helps you solve your issue.
(12-04-2019, 06:24 AM)burgoyn1 Wrote:(11-30-2019, 05:41 AM)midhunlalkc Wrote: Am also experiencing the same issue with routes with parameters TRY : Backend/Users to Backend\Users
TRY : Backend/Users to Backend\Users
[/quote] I also have this issue and worked out that changing / to \ works. The line of code that doesn't play well with the "controllers in folders" is in vendor\codeigniter4\framework\system\Router\Router.php (:660) Code: list($controller, $method) = array_pad(explode('::', $segments[0]), 2, null); So... This works Code: $routes->get('about', 'Front/Main::about'); Code: $routes->get('products/(children|men|women)', 'Front/Main::getProducts/$1'); Code: $routes->get('products/(children|men|women)', 'Front\Main::getProducts/$1'); I'm quite happy to use / but I would like to know if I may get bitten further down the road? ![]()
/ is for folder names or URL: blog/en/some-article
\ is for namespaces: App\Controllers\Blog::index
You both need to add the namespaces.
PHP Code: $routes->get('/movie/test/(:any)', 'MovieController::test/$1', ['namespace' => 'Dashboard']); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |