SOLVED: CI 4.0.2 and subdirectories - 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: SOLVED: CI 4.0.2 and subdirectories (/showthread.php?tid=75755) |
SOLVED: CI 4.0.2 and subdirectories - mariofix - 03-12-2020 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 RE: CI 4.0.2 and subdirectories - Bennito254 - 03-13-2020 I am facing the same problem for the Controllers and the Views too RE: CI 4.0.2 and subdirectories - InsiteFX - 03-13-2020 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 RE: CI 4.0.2 and subdirectories - juancarlosv - 04-03-2020 (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/incoming/controllers.html#defining-a-default-controller RE: CI 4.0.2 and subdirectories - anmar_dev - 04-03-2020 Same issue, i spend sometimes to figure out the right way... Agree with @juancarlosv. please add it to the documentation. RE: CI 4.0.2 and subdirectories - mariofix - 04-12-2020 (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; RE: SOLVED: CI 4.0.2 and subdirectories - BraveGhost - 08-24-2020 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. |