okfsoft/ci4-hmvc

CodeIgniter v4 HMVC

v1.0.0 2022-07-15 00:46 UTC

This package is auto-updated.

Last update: 2024-11-15 05:10:50 UTC


README


mscodev

CODEIGNITER 4 HMVC STARTER

License Latest Stable Version Latest Unstable Version Total Downloads

≡ 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



≡ Requirements



≡ Feature list

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

  • HMVC Architecture
  • BaldeOne Templating Engine


≡ Preparation & Installation

To get ready to install packages, you have to install codeigniter 4 appstarter with composer, or you can follow the user guide 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.

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

01. Install library via composer:

composer require okfsoft/ci4-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

( 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

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

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

<?php
$routes->group('home', ['namespace' => $hmvcNamespace], function ($routes) {
	$routes->get('/', 'Home::index');
	$routes->match(['get', 'post'], "(:any)", "home::$1");
});

You can use BladeOne Rendering which comes in the package. or use with the help of Class Helper


≡ Helpers



More info useful link

Credit