I need to generate a model file without the use of Gii. Are there any command Yii?
$table = "myTable";
Yii::app()->generateModel($table); // ?
I need to generate a model file without the use of Gii. Are there any command Yii?
$table = "myTable";
Yii::app()->generateModel($table); // ?
Don't think there is a command. You could create the model, or the command, yourself. Other option would be to make the requests to Gii via curl.
Perhaps is officially deprecated, you can generate code with Yii Command Line Tools
I have tested it with Yii 1.1.17.
First you need to create a new file on
protected/commands
called for exampleNewmodelCommand.php
to create a new yii command. We need to avoid to use shell interactive tool and call command directly from our code in controllers, models, etc. To get it, we inherit Yii core classModelCommand
. This class originally force person to type on interactive shell.That is all. You can test command from CLI into your operating system. In Linux, open your terminal and go to
/protected/
directory and type:You will see something like this:
Play a little with it. Type again:
And you will see all command help and documentation.
To generate a model with this command you need at least
model_name
as first parameter. Command will use same model name as database table name:If you have different model and database name:
If you have troubles using yiic, locating/connecting your db, etc, make sure to setup properly your console environment on protected/config/console.php and check all official docs about Yii console applications.
Finally in your code you can use your command as you want: