Routing issue with $routes->post - 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: Routing issue with $routes->post (/showthread.php?tid=74291) Pages:
1
2
|
Routing issue with $routes->post - ogomez - 09-06-2019 Every time I try to post to the create news. CI is not finding the route. Am I doing something wrong? Tested this using postman. Controller PHP Code: <?php namespace App\Controllers\api; Routes PHP Code: $routes->get('api/news', 'App\Controllers\api\News::getNews'); Thanks in advance RE: Routing issue with $routes->post - InsiteFX - 09-07-2019 Did you try using route groups? PHP Code: $routes->group('api', ['namespace' => 'App\Controllers\api'], function($routes) Remember you need to use the correct namespace also. RE: Routing issue with $routes->post - ogomez - 09-09-2019 Same result, I do have the namespace correct on my routes although the grouping looks much nicer. The routing is still incorrect. PHP Code: $routes->post('api/news', 'App\Controllers\api\News::createNews'); Thanks RE: Routing issue with $routes->post - includebeer - 09-10-2019 PHP Code: namespace App\Controllers\api; Is you News controller in the 'api' subdirectory? RE: Routing issue with $routes->post - ogomez - 09-10-2019 (09-10-2019, 02:47 AM)includebeer Wrote: Yes RE: Routing issue with $routes->post - includebeer - 09-10-2019 Are you sure the form is posted to the right URL? Show your opening form tag. RE: Routing issue with $routes->post - ogomez - 09-10-2019 (09-10-2019, 08:16 AM)includebeer Wrote: Are you sure the form is posted to the right URL? Show your opening form tag. I'm using it as an API end point. Testing it with postman. Sending a post request. controllers/api/news.php Controller PHP Code: <?php namespace App\Controllers\api; Route: PHP Code: $routes->group('api', ['namespace' => 'App\Controllers\api'], function($routes) { RE: Routing issue with $routes->post - includebeer - 09-10-2019 (09-10-2019, 09:23 AM)ogomez Wrote:(09-10-2019, 08:16 AM)includebeer Wrote: Are you sure the form is posted to the right URL? Show your opening form tag. It doesn't matter if it's an html form or if you use postman. At what URL do you post the data? If CI doesn't find the route, maybe that route isn't configured at all or is misconfigured or you have an error in your post url. RE: Routing issue with $routes->post - ogomez - 09-10-2019 (09-10-2019, 10:09 AM)includebeer Wrote:(09-10-2019, 09:23 AM)ogomez Wrote:(09-10-2019, 08:16 AM)includebeer Wrote: Are you sure the form is posted to the right URL? Show your opening form tag. The route is configured correctly and I'm not seeing any errors on the logs. RE: Routing issue with $routes->post - includebeer - 09-11-2019 Ok, fine. If you don't want to give more info, then there's nothing more I can do. |