mufidjamaluddin / codeigniter4-hmvc
CodeIgniter4 HMVC starter app
Installs: 1 895
Dependents: 0
Suggesters: 0
Security: 0
Stars: 67
Watchers: 8
Forks: 39
Open Issues: 1
Type:project
Requires
- php: >=7.2
- codeigniter4/framework: ^4.2
Requires (Dev)
- mikey179/vfsstream: 1.6.*
- phpunit/phpunit: 8.5.*
README
This is Hierarchical model–view–controller (HMVC) project starter using CodeIgniter4 framework. By HMVC architecture, I hope we could make scalable web application.
Prerequisites
- PHP 7.2 or above
- Composer version 1.10 or above
- intl PHP extension (for formatting currency, number and date/time, see CodeIgniter4 Docs )
- xdebug PHP extension (for testing purpose only, optional)
- php_sqlite3 PHP extension (for testing purpose only, very optional)
How to use
- Run
composer create-project mufidjamaluddin/codeigniter4-hmvc your_project
, to create your project based on this boilerplate. - Configure the app by change the
env
file. - Run
php spark serve
for run the app.
Make new module
Tutorial
- Update the spark files
composer update
cp vendor/codeigniter4/framework/public/index.php public/index.php
cp vendor/codeigniter4/framework/spark .
-
Call the
php spark module
command, then input a module, controller, and model name (Automatically configure a routes modules). -
Run
composer test
for run your test cases (optional, see CodeIgniter4 Docs or PHPUnit Docs ) -
Run in the browser by
php spark serve
command
Screenshot Example
Notes
Always run php spark route:update
after create or change module, controller, or controller methods directly without php spark module
command except if you want to configure module route manually.
Command Prompt
Command module, controller, and model creation
The easiest way to create a controller (required) and a model inside a module. Create a module or a model if it doesn't exist.
Usage: Call the php spark module
command, then input a module, controller, and model name.
Command route:update parameter
Parameters: '-n' = Set module namespace (default App\Modules) '-i' = Set route with /index path without parameter (true/false, default true) '-m' = Set route one module name to be create/update (app/Modules/YourModuleName) '-f' = Set module folder inside app path (default Modules)
Usage command php spark route:update -i false -m YourModule
Command module:create parameter
Example php spark module:create invoice
First parameter (invoice) is your new module.
PHPUnit
You can run all of your test cases by run composer test
Other Command
You can get all command prompt list by run php spark list
and composer command in composer.json > scripts.
HMVC Structure
Default Structure
By default, there is the structure of Codeigniter4-HMVC.
app
\Modules
\{YourModule}
\Config
Routes.php
\Controllers
BaseController.php
{YourController}.php
\Models
{YourModel}.php
\Views
\template
{YourTemplate}.php
\{your view module folder}
{Your View}.php
...
\tests
\unit
...
\integration
\Modules
\{YourModule}
{YourController}.php
...
Custom Structure
You can structuring your module freely, because CodeIgniter4 use PSR4. If you want to change the structure of Routes.php in Config Module folder or the structure of Module Controllers, you must change app/Config/Routes.php in HMVC Routing section and modify RouteUpdate.php & Module.php in app/Commands folder.
Contribute
You can contribute for extend CodeIgniter4 capabilities or add command prompt for development use by fork this repository. After that, you can make pull request.