SOLVED: CI 4.0.2 and subdirectories |
03-12-2020, 02:35 PM
(This post was last modified: 04-12-2020, 02:13 PM by mariofix. Edit Reason: Solved problem )
Hi! I've just been playing with CI 4.0.2 and I noticed I can't use subdirectories in my Controllers folder, everything else works fine, I installed via composer.
I have $routes->setAutoRoute(true); in Routes.php if i use this address http://localhost:8080/home works fine, but if create a directory and put the same Home.php file, I get a 404 error Controllers/Home.php -> http://localhost:8080/home (Works) Controllers/dot2/Home.php -> http://localhost:8080/dot2/home or http://localhost:8080/dot2/home/index (Doesn't Work) I get this error 404 - File Not Found Controller or its method is not found: App\Controllers\Dot2::Home Have you encounter the same problem? Thanks!! -mariofix
You need to namespace all folders and sub-folders.
If in the Controllers directory then: PHP Code: <?php If the Controller is in a sub directory: PHP Code: <?php When extending or using a Controller from a sub directory: PHP Code: use App\Controllers\sub-directory What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(03-13-2020, 08:14 AM)InsiteFX Wrote: You need to namespace all folders and sub-folders. Please, add it info in documentation: https://codeigniter4.github.io/userguide...controller
Same issue, i spend sometimes to figure out the right way...
Agree with @juancarlosv. please add it to the documentation.
I enjoy coding in codeigniter4. SurveyIgniter a project where i learn about codeigniter4.
(03-13-2020, 08:14 AM)InsiteFX Wrote: You need to namespace all folders and sub-folders. Excellent! Thank you, it's working now. a few things before: - Yes, you need to add the folder name into the namespace - the folder must start with an upper-case letter - The folder has the same rules as any Controller file (I think) PHP Code: <?php namespace App\Controllers\Dot2;
Thank you so much, I had same problem also, this solved my problem too, I checked documentation first but couldn't find the best explanation about it there.
|
Welcome Guest, Not a member yet? Register Sign In |