Codeigniter 4 doesn't detect Home controller in subdirectory |
I have an earlier post relating to this where I am trying to support URLs with dashes in them. Long story short, I must use dashes in my controller subdirectory names if I want to have dashes in my url. For whatever reason, the CI4 auto-routing is unable to recognize when a url with a dash in the path is referring to a controller subdirectory with an underscore.
E.g., if I want this url to connect to the default Home controller in my nested-directory subdirectory: Code: https://www.example.com/subdir/nested-directory PHP Code: namespace App\Controllers\Subdir\Nested_directory; That same url does not work if I put it in a directory with an underscore: app/Controllers/Subdir/Nested_directory/Home.php. Curiously, it looks like the dash in the url I request does get properly routed to an underscore while CI4 is calculating the controller path, however CI4 doesn't bother to check if the url is requesting the default Home controller in a subdirectory. The complaint it gives is: Code: Controller or its method is not found: \App\Controllers\Subdir\Nested_directory::index So it almost works, is just doesn't bother checking for the default controller in a subdir. Additionally, if I change my url to have an underscore in it, then CI4 can locate the Home controller in the subdirectory named with an underscore. This url: Code: https://www.example.com/subdir/nested_directory In my prior post mentioned above, it was enough to just make sure I name my subdirectories with dashes so they match the urls, however this does not work when i try do a $routes->add to a controller that happens to live in a subdirectory with a dash. This works just fine in my Config/Routes file if [b]Nested_directory contains an underscore: PHP Code: $routes->add("foobar/([0-9]+)", "Subdir\Nested_directory\Home::index/$1"); But if if the Nested-directory subdirectory containing my Home controller contains a dash, meaning my Home controller file is app/Controllers/Subdir/Nested-directory/Home.php, this will not work: PHP Code: $routes->add("foobar/([0-9]+)", "Subdir\Nested_directory\Home::index/$1"); PHP Code: $routes->add("foobar/([0-9]+)", "Subdir\Nested-directory\Home::index/$1"); Please note that I need to have these dashes instead of underscores because that is recommended by Google. I also very much do not want to create a big, complicated Routes file. The auto-routing of CI3 was working just fine. I think this problem could be remedied with a small code change. For reference, here is my Config/Routes.php file PHP Code: <?php namespace Config; |
Welcome Guest, Not a member yet? Register Sign In |