CodeIgniter Forums
Modules code example for codeigniter 4 - 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: Modules code example for codeigniter 4 (/thread-76888.html)



Modules code example for codeigniter 4 - cvlancvlan - 06-30-2020

If i don't use routes for this app/Modules/Product/Controllers/ProductController.php how can i acces this controller from url ?
If i use this route then url for this controller app/Modules/Product/Controllers/ProductController.php is sitename[.]ext/productx

Hou can i route all controller class from this path App/Modules/Controllers/ to this url sitename[.]ext/module/controller/method/params...
This is possible in codeigniter 4 ?

app/Config/Routes.php

PHP Code:
$routes->group('', ['namespace' => 'Modules\Product\Controllers'], function($routes){
    
$routes->get('productx''ProductController::index');
}); 

app/Config/Autoload.php

PHP Code:
$psr4 = [
    
'App'                 => APPPATH,
    
APP_NAMESPACE         => APPPATH,
    
'Config'              => APPPATH 'Config',
    
'Modules\Product'     => APPPATH 'Modules/Product',
]; 

app/Modules/Product/Controllers/ProductController.php

PHP Code:
<?php namespace Modules\Product\Controllers;
use 
CodeIgniter\Controller;

class 
ProductController extends Controller {
    
    public function 
index() {
        echo 
"productx index";
    }