PHPackages                             okfsoft/ci4-hmvc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. okfsoft/ci4-hmvc

ActiveLibrary[Framework](/categories/framework)

okfsoft/ci4-hmvc
================

CodeIgniter v4 HMVC

v1.0.0(3y ago)21012MITPHPPHP ^7.4 || ^8.1

Since Jul 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/okfsoft/ci4-hmvc)[ Packagist](https://packagist.org/packages/okfsoft/ci4-hmvc)[ Docs](https://github.com/okfsoft)[ RSS](/packages/okfsoft-ci4-hmvc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

 [![mscodev](https://raw.githubusercontent.com/okfsoft/art/master/logo/okf-logo.png)](https://raw.githubusercontent.com/okfsoft/art/master/logo/okf-logo.png)### CODEIGNITER 4 HMVC STARTER

[](#codeigniter-4-hmvc-starter)

---

[![License](https://camo.githubusercontent.com/49b07ceab5d700f1b1e8a9bee61decc71e4e52843760f43d6a036a19a5b1ebf1/687474703a2f2f706f7365722e707567782e6f72672f6f6b66736f66742f6369342d686d76632f6c6963656e7365)](https://packagist.org/packages/okfsoft/ci4-hmvc)[![Latest Stable Version](https://camo.githubusercontent.com/438116aa56ab4c003ab4501be0f59b224d4b9332cdba437edd8ea3fa342f893a/687474703a2f2f706f7365722e707567782e6f72672f6f6b66736f66742f6369342d686d76632f76)](https://packagist.org/packages/okfsoft/ci4-hmvc)[![Latest Unstable Version](https://camo.githubusercontent.com/de8e64450f041dafb1089dc67912c2665f0f701ec16bd851ec7575046e8b4c59/687474703a2f2f706f7365722e707567782e6f72672f6f6b66736f66742f6369342d686d76632f762f756e737461626c65)](https://packagist.org/packages/okfsoft/ci4-hmvc)[![Total Downloads](https://camo.githubusercontent.com/e8d445289d5012fde0084cd64dd7343a54197d1838aa1a7b349b86f9beccd2a1/687474703a2f2f706f7365722e707567782e6f72672f6f6b66736f66742f6369342d686d76632f646f776e6c6f616473)](https://packagist.org/packages/okfsoft/ci4-hmvc)

≡ About ci4-hmvc
================

[](#-about-ci4-hmvc)

This is a project archive that we use to make it easier for us to build web applications based on the CodeIgniter4 framework. Hopefully it can be useful.

CodeIgniter is a php based framework and works on the MVC (Model-View-Controller) pattern. Can also use Hierarchical Model View Controller (HMVC). HMVC stands for Hierarchical Model View Controller. This is the latest version of the HMVC pattern used for web applications. Provide solutions to help you address application scalability such as easy module updates.

≡ Table of contents
===================

[](#-table-of-contents)

- [Requirements](#-requirements)
- [Feature List](#-feature-list)
- [Installation Preparation](#-preparation--installation)
    - [Install via composer](#install-library-via-composer)
    - [Setup HMVC](#02-distribute-hmvc)
    - [Config File](#03-modify-autoloadphp)
- **How to use**
    - [Use of HMVC](#-use-of-hmvc)
    - [Router Settings](#01-router-settings)
    - [Helpers](#-helpers)
- [Credit](#credit)

≡ Requirements
==============

[](#-requirements)

- [Framework Codeigniter 4.2.1](https://github.com/codeigniter4/framework)
- [PHP 7.4 or higher](https://www.php.net/releases/8.1/en.php)

≡ Feature list
==============

[](#-feature-list)

This is a list of some features or functionality that you can use.

- HMVC Architecture
- BaldeOne Templating Engine

≡ Preparation &amp; Installation
================================

[](#-preparation--installation)

To get ready to install packages, you have to install codeigniter 4 appstarter with composer, or you can follow the [***user guide***](https://codeigniter4.github.io/userguide/installation/installing_composer.html) to install using composer.

Now the next step is to add the rule in composer.json in your project root, and add the following rule to make it work after the installation is complete, or you can skip this preparation and add it manually in [step number 03](#03-modify-autoloadphp).

```
+    "autoload": {
+        "psr-4": {
+            "Modules\\Application\\": "modules/application",
+            "Modules\\Resources\\": "modules/resources"
+        }
+    }
```

#### 01. Install library via composer:

[](#01-install-library-via-composer)

```
composer require okfsoft/ci4-hmvc
```

#### 02. Distribute HMVC

[](#02-distribute-hmvc)

Now you can distribute the library can be done via spark:

```
php spark hmvc:publish
```

This will copy and distribute the sample hmvc structure folder in your project root parallel to the codeigniter4 `app` folder.

#### 03. Modify Autoload.php

[](#03-modify-autoloadphp)

( *Ignore rule number 03 if you have added autoload in composer.json* ).
Next you need to modify psr-4 settings on Autoload.php file on `app/Config/Autoload.php` and add below rules

```
public $collectors = [
    public $psr4 = [
        APP_NAMESPACE         => APPPATH, // For custom app namespace
        'Config'              => APPPATH . 'Config',
+       'Modules\Application' => ROOTPATH . 'modules/application',
+       'Modules\Resources'   => ROOTPATH . 'modules/resources',
    ];
];
```

≡ Use of HMVC
=============

[](#-use-of-hmvc)

You can try running `php spark serve` to run codeigniter development and visiting `http://localhost:8080/starter` it will load hmvc `modules/application/Starter` which will show if there are no problems during installation.

When you `http://localhost:8080/starter/blade` will load hmvc starter using BladeOne Template Engine

#### 01. Router Settings

[](#01-router-settings)

You can make `Routes.php` settings for each new module created in the `modules/application/{Module_name}/Config.php` directory, using this code sample:

```
