Welcome Guest, Not a member yet? Register   Sign In
Need Help with Modules
#1

Hello! I'm trying to add independent modules to my application. I am following the official Guide.

https://codeigniter4.github.io/userguide...dules.html

But seems like I missed something... Cause I am getting a 404 error when I try to access to the Default Home Controller of my Blog Module.

Basically the first thing I did is create a new folder in the Project Root

app/
public/
system/
writable/
modules/
modules/Blog/
modules/Blog/config/
modules/Blog/Controllers/
modules/Blog/Models/...
...
...


Then I create a new namespace for this modules folder in app/Config/Autoload.php
PHP Code:
        $psr4 = [
            
'App'         => APPPATH,                // To ensure filters, etc still found,
            
APP_NAMESPACE => APPPATH,                // For custom namespace
            
'Config'      => APPPATH 'Config',
            
'Modules'     => ROOTPATH 'Modules'    // MODULES
        
]; 


After that I add that to the Active Explorers (I am not sure what I have to add here... The name of the Namespace? Folder?) app/Config/Modules.php
PHP Code:
    public $activeExplorers = [
        
'events',
        
'registrars',
        
'routes',
        
'services',
        
'modules'
    
]; 


Next Step is add the Route to the app/Config/Routes.php
PHP Code:
$routes->group('blog', ['namespace' => 'Modules\Blog\Controllers'], function($routes)
{
    $routes->get('/''Home::index');
}); 


But I got a 404 when I call this route... (baseURL)/blog

modules/Blog/Controllers/Home.php - I dont know if have to change the namespace inside Blog Controller... But I tried too... and still the same.
PHP Code:
<?php namespace App\Controllers;
// namespace Modules\Blog\Controllers; Not Working Neither

class Home extends BaseController
{
    public function 
index()
    {
        return 
view('welcome_message');
    }

    
//--------------------------------------------------------------------



Thanks.
Reply


Messages In This Thread
Need Help with Modules - by Programaciones Web - 02-26-2020, 10:48 AM
RE: Need Help with Modules - by InsiteFX - 02-26-2020, 04:05 PM
RE: Need Help with Modules - by InsiteFX - 02-27-2020, 03:23 PM
RE: Need Help with Modules - by MGatner - 03-01-2020, 09:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB