When I work on an existing CodeIgniter project, I usually just copy/paste from previous work: if I need to create a new controller, I simply copy an existing controller that looks similar to what I want to do in the new controller and paste it as the new controller. After that I delete what I don’t need (sometimes that means about 75% of the copied code).
Why do I do this? Because I simply need a template, a boilerplate from which to start creating new code. The same happens with models, views, etc.
But now and then I need to create a new project, and I find myself staring at an empty screen because I forgot how to start the file (the “copy/paste effect”).
So why not use an “artisan”, or an “oil”, or whatever for CodeIgniter. I mean why not simply create a php CLI script that would allow us to create a boilerplate for controller, models, views, etc. whenever we need.
We simply write inside the console: php index.php matches create:controller Welcome, and the controller is created for us to start coding.
Having this in mind I’ve written such a script some time ago, and found myself returning to it when I create a new CodeIgniter project.
You can also use it on its Github repository: https://github.com/avenirer/codeigniter-matches-cli
To install, you simply copy the files in their respective locations. After that, take a look inside the configuration file matches.php. Maybe you want to change something in there, who knows…
And you are ready to go. So open the console (command prompt), go inside your project (where the main index.php – bootstrapper – of your application is) and say hello to the Matches:
php index.php matches
If you are greeted by the new controller, then start using it:
For example this line below…
php index.php matches create:controller hello e=admin
…will create a controller named Hello that will extend Admin_Controller.
More info regarding the usage you can find on the Matches repository. Do give it a try and tell me your opinion or maybe anything else you think would be great to implement.