从现有实体 Symfony4 生成表单

Generate Form from exist Entity Symfony4

我在数据库中有一个 table,它有很多列。我知道 EasyAdminBundle 在那里,我过去用它来创建基于数据库 tables 的表单。如何基于实体创建它?这样我就可以自动生成表格,而无需手动填充它们。

可以使用Symfony Maker Bundle. With this bundle, you can generate code if you are using a version of Symfony later than 3.4. For older versions you can use Sensio Generator Bundle

在您的情况下,使用 composer 安装 Maker Bundle:

composer require symfony/maker-bundle --dev

然后 运行 此命令(并按照步骤)创建您的表单:

php bin/console make:form

要查看您可以使用的所有 make 命令,运行 php bin/console list make

作为 symfony 4.4 你可以这样做:

./bin/console make:entity YourFormType \\Your\\Path\\To\\Entity

来自命令帮助:

说明: 创建新表单 class

用法:

make:form [ <name> [<bound-class>]]