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.
- Requirements
- Feature List
- Installation Preparation
- How to use
- Credit
This is a list of some features or functionality that you can use.
- HMVC Architecture
- BaldeOne Templating Engine
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"
+ }
+ }
composer require okfsoft/ci4-hmvcNow you can distribute the library can be done via spark:
php spark hmvc:publishThis will copy and distribute the sample hmvc structure folder in your project root parallel to the codeigniter4 app folder.
( 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',
];
];
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
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
| Parameter | Information |
|---|---|
return renderView('home', $data); |
HMVC Display Rendering using Default |
return renderBlade('home', $data); |
HMVC Display Rendering using BladeOne |