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

試著忘記壹切 提交于 2019-11-27 18:26:05

问题


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?


回答1:


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!




回答2:


You can generate entities from an existing database like this

Then you can generate CRUD forms for those entities like this

There is no native way to create scaffolding directly from the DB. You have to go through this two step process.



来源:https://stackoverflow.com/questions/16695463/is-there-a-facility-for-generating-scaffolding-in-a-symfony2-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!