Simpletine / CodeIgniter-4-HMVC

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.

Home Page:https://github.com/Simpletine/CodeIgniter4-HMVC

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

https://github.com/Simpletine/CodeIgniter4-HMVC

License:MIT License


Languages

Language:PHP 97.8%Language:CSS 1.0%Language:JavaScript 1.0%Language:Smarty 0.2%Language:HTML 0.0%Language:Hack 0.0%