Symfony3表单错误-名称为空的表单不能具有父表单

时间:2018-08-17 10:57:02

标签: php forms symfony

我的代码运行良好,直到今天早上,我都报错

[2018-08-17 12:39:42] request.INFO: Matched route "white_label_homepage". {"route":"white_label_homepage","route_parameters":{"_controller":"Bundle\\WhiteLabelBundle\\Controller\\DefaultController::indexAction","_route":"white_label_homepage"},"request_uri":"http://symfony/white-label","method":"GET"} []
[2018-08-17 12:39:42] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Form\Exception\LogicException: "A form with an empty name cannot have a parent form." at /home/symfony/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 270 {"exception":"[object] (Symfony\\Component\\Form\\Exception\\LogicException(code: 0): A form with an empty name cannot have a parent form. at /home/symfony/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php:270)"} []

我不想跳过所有代码,但是没有关于此错误的解释,无法在Internet上找到:)。因此,如果有人可以详细说明此错误是什么意思。在docs中,没有为表单设置名称,也没有父项,那么这个错误是什么呢?

1 个答案:

答案 0 :(得分:1)

如果您不小心将空字符串传递给表单构建器的add()方法,则会发生以下示例中的情况:

$builder->add('');