A powerful CLI tool for generating modular structures in CodeIgniter 4 applications, specifically designed for the ci4ms framework. The ModuleGenerator
simplifies the creation of standardized module structures, including configuration files, controllers, views, and language files.
The ModuleGenerator
is a CodeIgniter 4 CLI command that creates a complete module structure with a single command. It follows CodeIgniter 4 conventions and best practices, making it an essential tool for developers building modular applications with the ci4ms framework.
To use the ModuleGenerator
, install it via Composer:
composer require ci4-cms-erp/ext_module_generator
Run the following command in your CodeIgniter 4 project directory to create a new module:
php spark make:module ModuleName
If no module name is provided, the CLI will prompt you to enter one. The module name will be automatically capitalized (e.g., user
becomes User
).
$ php spark make:module Admin
Module 'Admin' created successfully!
$ php spark make:module Blog
Module 'Blog' created successfully!
This will generate modules named Admin
and Blog
in the modules
directory with all necessary files and folders.
The ModuleGenerator
creates the following directory structure for each module:
modules/ModuleName/
├── Config/
│ ├── ModuleNameConfig.php
│ └── Routes.php
├── Controllers/
│ └── ModuleName.php
├── Database/
│ ├── Migrations/
│ └── Seeds/
├── Helpers/
├── Language/
│ ├── en/
│ │ └── ModuleName.php
│ └── tr/
│ └── ModuleName.php
├── Libraries/
├── Models/
├── Validation/
└── Views/
├── create.php
├── list.php
└── update.php
Each directory and file serves a specific purpose, adhering to CodeIgniter 4 conventions.
The generator creates the following template files with predefined content:
en/ModuleName.php
) and Turkish (tr/ModuleName.php
) language files with welcome messages.create.php
, list.php
, and update.php
views, integrated with a base layout.Below is an example of the generated controller for a module named Blog
:
namespace Modules\Blog\Controllers;
class Blog extends \Modules\Backend\Controllers\BaseController {
public function index() {
return view('Modules\Blog\Views\list', $this->defData);
}
public function create() {
if ($this->request->is('post')) {
$vdata = [
''=>['label'=>'', 'rules'=>''],
];
$valData = ($vdata);
if ($this->validate($valData) == false) return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
return view('Modules\Blog\Views\create', $this->defData);
}
public function update(int $id) {
if ($this->request->is('post')) {
$vdata = [
''=>['label'=>'', 'rules'=>''],
];
$valData = ($vdata);
if ($this->validate($valData) == false) return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
return view('Modules\Blog\Views\update', $this->defData);
}
public function delete(int $id)
{
$infos=$this->commonModel->selectOne('your_table',['id'=>$id]);
if($this->commonModel->remove('your_table',['id'=>$id]))
return $this->redirect()->back()->with('success',$infos->attr.' deleted.');
return $this->redirect()->back()->with('error','Can not deleted.');
}
}
The ModuleGenerator
uses template methods to generate files, allowing developers to customize the templates in the ModuleGenerator.php
class to fit specific project requirements.
This project is licensed under the MIT License.
Contributions are welcome! Please submit a pull request or open an issue on the project’s GitHub repository.
For issues or questions, refer to the GitHub repository or contact the maintainers.
Made with ❤️ for the CodeIgniter community
© 2025 - All rights reserved