Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 4 dynamic routing to controller
#5

(This post was last modified: 12-13-2022, 04:02 AM by kaligula.)

(12-13-2022, 02:02 AM)kenjis Wrote: If you add the module namespace in the app/Config/Autoload.php, the route file in the module will be loaded automatically.

Read https://codeigniter4.github.io/CodeIgnit...dules.html

Yeah, i know. I speaking about like that: 

PHP Code:
    $modules array_map('basename'glob(getcwd() . '/modules/Admin/*' GLOB_ONLYDIR));
    foreach($modules as $module)
    {
        $psr4['Admin\\'.$module] = ROOTPATH 'modules/Admin/'.$module;
    

Can I implement something like that to Autoloader.php? I need to do this, because if admin submodule folder exist in my Admin module folder – i need this module, but i don't wanna on each project connect each module and write this config to Autoloader.php by my own.


UPD. I think i found a solution, but is it a good idea to do this like that?

Add this to app/Config/Autoloader.php at bottom of a file:

PHP Code:
public function __construct()
    {
        
parent::__construct();


        
$modules array_map('basename'glob(getcwd() . '/modules/Admin/*' GLOB_ONLYDIR));
        foreach(
$modules as $module)
        {
            
$this->psr4['Admin\\'.$module] = ROOTPATH 'modules/Admin/'.$module;
        } 
    } 
Reply


Messages In This Thread
RE: Codeigniter 4 dynamic routing to controller - by kaligula - 12-13-2022, 02:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB