Controller in subdirectory - 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: Controller in subdirectory (/showthread.php?tid=79463) |
Controller in subdirectory - TaylorHicks - 06-19-2021 My folder structure is /App/Controllers/Api I have a file named Internal.php with a class name Internal that extends Controller the class has only one public method named bounce I expected to be able to access the method at '/api/internal/bounce' but I get a 404 instead at that url. If I move my controller to the /App/Controllers directory I am able to access the method at '/internal/bounce' Can someone help point me in the correct direction? Here is my routes file if it helps PHP Code: <?php RE: Controller in subdirectory - venance - 06-19-2021 You need to specify the namespace and the namespace of the extended class or BaseController. PHP Code: //routes RE: Controller in subdirectory - TaylorHicks - 06-19-2021 Thank You for your prompt reply. I have the Controller namespaced and I am extending CodeIgniter\Controller rather than BaseController because my base controller has a lot of code for rendering my sites template pages that I didn't want to load for an API Call thats going to return json. I will probably make a new class 'ApiBaseController' in the near future to extend for my api controllers. I was hoping to take advantage of the auto -outing feature so I didn't have to declare the routes for every api call and remember to change them if I change something in the future. This is just the first of many Controllers/Methods that will be implemented in this folder and I was hoping to get it working as it is described here CodeIgniter4 Controllers in Sub-Directories. Edit: I got it working by changing the namespace from 'App\Controllers' to 'App\Controllers\Api' PHP Code: namespace App\Controllers; RE: Controller in subdirectory - venance - 06-24-2021 Nice if you have solved the issue. RE: Controller in subdirectory - InsiteFX - 06-24-2021 namespace App\Controllers\SubDirectoryName; |