Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

php - is there a facility for generating scaffolding in a Symfony2 app?

I've been doing searches on scaffolding in Symfony 2 and keep finding references to "generators" but so far have not been able to get scaffolding up and working.

By "scaffolding" I'm referring to a way to point your tool at a database and have it generate views/forms to perform CRUD operations.

This can be useful for quickly prototyping something, and/or build a rough admin tool for some of your database tables.

It can also provide a starting point for some form you are building.

Is this possible in Symfony2?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Crud operations are provided by the SensioGeneratorBundle which is included in the symfony standard distribution.

You can use the following command to generate form, templates & controller for existing entitites. It is interactive and can also update your routing automatically.

app/console generate:doctrine:crud

entity classes themselfes can be created with another command - interactive aswell.

 app/console generate:doctrine:entity

Generating entities from database is done with:

app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force

which will create xml mapping files. Afterwards you can generate entities as follows:

app/console doctrine:mapping:import AcmeBlogBundle annotation
app/console doctrine:generate:entities AcmeBlogBundle

This would generate the entities with annotations. yml and xml are supported aswell!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...