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.

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
- CodeIgniter 4 Query Parameter Binding with examples in MySQL
- CodeIgniter 4 Query Builder join() Method Explained
- OpenLampTech issue #15 – CodeIgniter 4 select() methods in depth
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
- Need hosting for your next web application or WordPress site? I highly recommend Hostinger and use them to host my niche bass fishing site. The service is second to none.
- 🔒5 Truths I’ve Come To Realize As a Self-taught Developer
- Desktop and mobile wallpapers, digital downloads, photography services, Shopify and WooCommerce customizations, and content writing – all in one E-commerce Shop. Find your next digital purchase today!
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!