Is there a way to automatically generate models from a MySQL DB in YII?
1 Answer
You can use Gii to generate models, views and controllers for CRUD operations from tables.
You can enable Gii by inserting this code in your configuration file (uncomment it from the by yiic generated code).
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'****',
'ipFilters'=>false, // Not recommended, but easy.
),
),
Then browse to example.com/index.php?r=gii. Login to Gii and from there the process speaks from itself.
When asked for the Model name enter * to create models for all tables in the database.
7 Comments
The Bndr
+1 <- it's an half-automatic-model creation: Gii generates one model from one table, but Gii doesn't work in "batch mode". That means: it's not possible to generate models for all the tables at ones. You have to create the models step by step.
Asaf
I know for a fact that I've auto-generated models before on Yii. Sadly I don't remember how
thaddeusmt
Yii has (er, "had", it's been depreciated in favor of Gii) a command line tool for this, that could be called by a shell script or something to make it more "automatic". Or it could be modified to be more automatic. yiiframework.com/doc/guide/1.1/en/quickstart.first-app-yiic
Neil McGuigan
@The Bndr. not true. Just enter * for the model name and it will generate models for all tables.
k to the z
@the bndr schemaname.* will generate all the models. I'll recommended updating your yii framework copy.
|