Skip to content

Implementing HMVC with CodeIgniter 4: In this approach, we group the Model-View-Controller components into packages called Modules, each acting as a self-contained unit of the application. This method aims to enhance scalability and maintainability, making it a best practice for developing robust web applications.

License

Notifications You must be signed in to change notification settings

Simpletine/CodeIgniter4-HMVC

Repository files navigation

Codeigniter4-HMVC

Official Website
YouTube Channel

Prerequisites

  1. PHP 7.4 or above
  2. Composer required
  3. CodeIgniter 4.4.8

Installation Guide

For the guideline, see the documentation


Generate New Module

php spark make:module [module] 

Example

Create a blog module

php spark make:module blogs

Result Directory

App 
├── Config       
│   └── Routes.php (Added group called blogs)
├── Modules      
│   └── Blogs
│       ├──  Controllers
│           └──  Blogs.php
│       ├──  Models
│           └──  BlogsModel.php
│       └──  Views
│           └──  index.php
└── ...  

Route Group

After generate Blogs Module, add a route group for the module at App\Config\Routes.php

$routes->group(
    'blogs', ['namespace' => '\Modules\Blogs\Controllers'], function ($routes) {
        $routes->get('/', 'Blogs::index');
    }
);

PSR4

At App/Config/Autoload.php, you can configure your custom namespace:

public $psr4 = [
    // Sample
    "$module" => APPPATH . "$module",

    // Base on Example above
    "Blogs" => APPPATH . "Modules/Blogs", // Example 
    // ...
];

Contribute

To contribute to this repository and extend its architectural capabilities or you find an issue, follow these steps

About

Implementing HMVC with CodeIgniter 4: In this approach, we group the Model-View-Controller components into packages called Modules, each acting as a self-contained unit of the application. This method aims to enhance scalability and maintainability, making it a best practice for developing robust web applications.

Resources

License

Stars

Watchers

Forks