Controller in subdirectory |
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
You need to specify the namespace and the namespace of the extended class or BaseController.
PHP Code: //routes
06-19-2021, 04:54 PM
(This post was last modified: 06-19-2021, 05:08 PM by TaylorHicks. Edit Reason: Figured out my problem )
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;
namespace App\Controllers\SubDirectoryName;
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 |