It seems like every week or two I'm having to write another console command and going through the same steps to do so. I could not find an existing solution to fit my needs, so here it is, a very simple and easily customizable Gii command generator.
Update: I've written a blog post where I delve into customizing code generators, and cover this extension. If interested, see Tailoring code generators for your app.
Drop the included
command folder into the
protected/gii folder or wherever else you keep your Gii generators and template stuffs.
Modify the Gii
generatorPaths (this is within the
modules section) in
config/main.php to include a path alias to this folder, e.g.:
'gii'=>array( 'class'=>'system.gii.GiiModule', // 'password'=>'secret', // 'ipFilters'=>array('127.0.0.1'), // 'newFileMode'=>0666, // 'newDirMode'=>0777, 'generatorPaths'=>array( 'application.gii' ), ),
While in the config, make sure your deployment handles Gii paths (section
'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( ... 'gii'=>'gii', 'gii/<controller:\w+>'=>'gii/<controller>', 'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>', ... ),
By default, commands are created in a sub-directory of your script path (I use application.extensions for this, but you may be using application.commands or something else). There are also two options in CommandCode.php for specifying how to automatically form the class name, "Prefix" and "Uppercase First". With both set, for example, a new command named
simple-test would become
To create a new template to your preferences, just copy the included templates/default to templates/new and reload the Gii page in your browser - your 'new' template will then be selectable.