yiisoft / yii2-gii

Yii 2 Gii Extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
201 stars 191 forks source link

[ENH] Add Scaffold #285

Open pana1990 opened 7 years ago

pana1990 commented 7 years ago

Currently to generate crud we have to do the following steps:

  1. create migrate.
  2. run migrate.
  3. create model from gii.
  4. create crud from gii.

i suggest execute the following command (or gui with this fields ):

./yii gii/scaffold Post --fields="title:string:notNull, body:string:notNull, created_at:integer"

This should generates the following files :

I have to think better that features should have the generator but what do you think about it?

samdark commented 7 years ago

There are many parameters in Gii generators involved. Should this new scaffold have all these in a huge single form?

pana1990 commented 7 years ago

i imagine something like this one :

image

where it should put classes i have Doubts, rails use conventions over configurations i think it is the best option or set paths in config but i am not sure. personality i dont like write full namespace to generate classes.

Suggestions?

uldisn commented 7 years ago

Creating table structure in gii is wrong idea. For creating new table better is use specialised SQL management tools (I suggest use SqlYog). When table defined, get SQL statement and copy to migration.

cebe commented 7 years ago

related project: https://github.com/schmunk42/yii2-giiant It still uses migrations first approach but can build more complete models and crud from there.

pana1990 commented 7 years ago

@uldisn why?

use code to create schema tables vs uses pure sql has advantages and disvantages... but you still can use whatever like it. what is the problem?

tunecino commented 7 years ago

For more ideas you may also check this extension: https://github.com/tunecino/yii2-schema-builder it is a different concept, more about generating and running a sequence of command shell but the default sequence looks pretty much like the 4 steps you mentioned above but flexible enough to involve custom gii generators and console apps. Like rest for example may need custom gii crud generator that doesn't generate views and maybe other gii generator to generate url rules. You can try it for both web and rest within this template: https://github.com/tunecino/yii2-app-builder