CodeIgniter Forums
Testing Code Modules - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Testing Code Modules (/thread-73832.html)



Testing Code Modules - Matleyx - 06-10-2019

Hi!

I'm Matleyx, and i'm testing the code Module in CI4

You see my file in the attachment.

I modified the autoload file, adding this line in Psr4:


Code:
'Modules'                   => APPPATH.'../modules'

but i have a problem with Routes file.
I'll explain:

This is the line for routes.php

Code:
$routes->group('testmodule', ['namespace' => 'Modules\Testmodule\Controllers'], function($routes)
{
    $routes->add('/', 'Testcont::index');
    $routes->add('(:any)', 'Testcont::$1');

This work only if i put this line in /app/Config/Routes.php. (localhost/ci4/public/testmodule/ecc

If i put the lines in the /modules/Testmodule/Config/Routes.php, don't work.

How do I make it work with module/Testmodule/Config/Routes.php?

Thanks to all


RE: Testing Code Modules - kilishan - 06-10-2019

Each module needs it's own namespace defined:

Code:
'Modules\TestModule' => APPPATH.'../modules/Testmodule'



RE: Testing Code Modules - Matleyx - 06-10-2019

(06-10-2019, 06:05 AM)kilishan Wrote: Each module needs it's own namespace defined:

Code:
'Modules\TestModule' => APPPATH.'../modules/Testmodule'

In this mode it's work only with other function. Not with index function. 
In the module/testmodule/config/routes.php i have:
Code:
$routes->group('testmodule', ['namespace' => 'Modules\Testmodule\Controllers'], function($routes)
{
   $routes->add('/', 'Testcont::index');
   $routes->add('(:any)', 'Testcont::$1');
});
it's corrcet? Should be correct the index routing....

Another question:
In this way, all the module must be declared in autoload file.
is it possible to declare only the modules folder and have all the module/config/routes.php files self-autoload?


RE: Testing Code Modules - kilishan - 06-11-2019

It is not possible out of the box to list a parent folder and have it auto-discover the namespaces. This is done for performance reasons. You could fairly easily extend the autoloader to search for it as you'd like, though.


RE: Testing Code Modules - Matleyx - 06-19-2019

(06-11-2019, 06:24 AM)kilishan Wrote: It is not possible out of the box to list a parent folder and have it auto-discover the namespaces. This is done for performance reasons. You could fairly easily extend the autoloader to search for it as you'd like, thoug
Ok, Thanks