How can we use the Gii generators in our codes?

The Gii provides a web interface that allows us to use the generators.

Taking the model generator as an example, I already have the inputs in an array:




$arr=array(

	array('user','User'),

	array('post','Post'),

	array('comment','Comment'),

	//many table name and model name pairs go below

);

Rather than entering these data manually in the Gii web interface, I would like to directly supply them to the model generator.

Although I know the code files for model generator are located in framework/gii/generators/model, I can hardly find any function that takes a table name and model name as the parameters.

How can we directly use the Gii generators in our codes?

Many thanks to you all.

You have to take a look at the gii source code:

  • The generator uses the ModelCode.php (extends CCodeModel) as input from the gii form.

  • The CCodeGenerator.php creates the ModelCode instance and assigns the attributes tableName, modelClass … from the submitted $_POST.

So you have to create the ModelCode instance manually, set the attributes (see CCodeGenerator.prepare) and start the code generation like CCodeGenerator.actionCode.

But I think, it’s a little bit of work …

It seems quite complicated. I have decided to use the web interface manually.

Thanks for pointing me in the right direction anyway. :)