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.

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
license.txt
Notifications You must be signed in to change notification settings

Simpletine/CodeIgniter-4-HMVC

Repository files navigation

Codeigniter 4 HMVC

Official Website
YouTube Channel

Prerequisites

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

Installation Guide

Clone project to your project root folder

composer create-project simpletine/codeigniter4-hmvc ci4_hmvc --stability=dev

Or

git clone https://github.com/Simpletine/CodeIgniter4-HMVC.git ci4_hmvc

Then

cd ci4_hmvc

Copy some require file to root folder (Upgrading to v4.4.8)

composer update
cp vendor/codeigniter4/framework/public/index.php public/index.php
cp vendor/codeigniter4/framework/spark spark

Copy env file

cp env .env

Run the app, using different port, add options --port=9000

php spark serve

Module Commands

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 
    // ...
];

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.

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
license.txt

Stars

Watchers

Forks

Languages