Create CodeIgniter 4 Models With Command Line Generators

I’m all about saving time wherever I can in coding projects. In CodeIgniter 4, there are some handy commands you can use and save a lot of time setting up base file scaffolding: Command Line Generators (CLG). I recently explored using CLGs for Model scaffolding and was impressed with the time savings.

The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.

Image by OpenClipart-Vectors from Pixabay 

I was recently working on a CodeIgniter 4 application with different connections to different databases.

CodeIgniter 4: php spark command

It’s super-easy to make your base Model scaffolding with CLG in CodeIgniter 4. You can run the php spark command, in your project’s root folder, and generate the code.

If I want to make a Model named Important with the Model suffix, this command will do it:

php spark make:model Important --suffix

CodeIgniter 4: Multiple Database Connections

We can have different database connections in a project and make additional connection group arrays in the app/Config/Database.php file. If I need a separate connection to the Sakila database, I can create the below $sakilaGroup array with the connection information:

CodeIgniter 4: –dbgroup flag

If you want your Models to have a specific database connection group instead of the $defaultGroup, you can name the group for the –dbgroup flag in the CLG command when creating the Model.

php spark make:model Important2 --dbgroup sakilaGroup --suffix

The –dbgroup flag sets the protected $DBGroup class property in the Model as shown in the screenshot above.

Try CodeIgniter 4 Command Line Generators in your next project and save time on base code scaffolding for Models, Controllers, Entities, and several other classes.

CodeIgniter 4 Additional Reading


Thank you for reading this post. Please share it with someone else who would enjoy it as well.


Josh Otwell has a passion to grow as a PHP Developer, SQL expert, and technical blogger/writer.

Disclaimer: The majority of examples in this post, are performed in a personal development/learning workstation environment and should not be considered production quality or ready. Your particular goals and needs may vary. Like always, just because you can do something doesn’t mean you should. My opinions are my own.

More ways I can help

Disclosure: Some of this blog post’s services and product links are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.

The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.


📰 Get your brand, product, or service the attention it deserves with affordable classified ad placement in the OpenLampTech newsletter. I appreciate your support!


Hey thanks for commenting! Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.