admin管理员组

文章数量:1296330

I have different custom Module paths/ Namespaces in my CodeIgniter4 project, and I just recently upgraded to version 4.4.0. in this upgrade the route settings will move from Config/Routes.php to Config/Routing.php file.

Now while I load my modules/namespace routes; my module routes are not identified because the $defaultNamespace setup is now in a different file.

How can I handle this?

I have added the Routes path to the $routesFiles parameter in the Routing.php

public array $routeFiles = [
        APPPATH . 'Config/Routes.php',
        'BudgetingModule\Config/Routes.php',
        'FeeModule\Config/Routes.php',
    ];
   

I have different custom Module paths/ Namespaces in my CodeIgniter4 project, and I just recently upgraded to version 4.4.0. in this upgrade the route settings will move from Config/Routes.php to Config/Routing.php file.

Now while I load my modules/namespace routes; my module routes are not identified because the $defaultNamespace setup is now in a different file.

How can I handle this?

I have added the Routes path to the $routesFiles parameter in the Routing.php

public array $routeFiles = [
        APPPATH . 'Config/Routes.php',
        'BudgetingModule\Config/Routes.php',
        'FeeModule\Config/Routes.php',
    ];
   
Share Improve this question asked Feb 11 at 21:30 Olisa AgbaforOlisa Agbafor 333 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

I suspect your Routing includes are wrong. You currently have:

'BudgetingModule\Config/Routes.php',
'FeeModule\Config/Routes.php',

But you will need to make this something more like this:

'/var/www/html/path_to/BudgetingModule/Config/Routes.php',
'/var/www/html/path_to/FeeModule/Config/Routes.php',

Note also you have forward slashes and backslashes in the same path which might confuse things. Alternatively if your modules are in the APPPATH location you can replace the /var/www/html/path bit.

First, there is no need including the Route files in the $routeFiles since the modules are autoloaded and the Routes auto discovered.

But in each of the custom module config path, I included the Services.php file and in the Routes.php files, I brought back the former routes settings with the appropriate namespace to each of these files

in BudgetingModule\Config\Routes.php file

    namespace BudgetingModule\Config;

// Create a new instance of our RouteCollection class.
$routes = Services::routes();

$routes->setDefaultNamespace('BudgetingModule\Controllers');
$routes->setDefaultController('Index');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->setAutoRoute(false);

本文标签: codeigniterLoading Routephp and Routingphp settings in different Modules in CodeIgniter4Stack Overflow