首页 > 解决方案 > Symfony表单视图猜错方法?

问题描述

我使用 Symfony 5,并且我创建了 3 个类 Deal、DealCategory 和 DealSubCategory php bin/console make:entity。这些是这些类之间的关系。

这是这些课程的要点

https://gist.github.com/methodeprog/8ca704f89910284197e93cafb1f009de

然后在它们的 php bin/consolemake:crud之后

在交易表格中,当尝试创建交易时,我得到了这个。这很奇怪,请帮忙

Neither the property "dealCategory" nor one of the methods "dealCategory()", "getdealCategory()"/"isdealCategory()"/"hasdealCategory()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView".

奇怪的是,在我的 Deal 类方法中没有 getdealCategory() 而是 getDealCategory()...

为什么 Symfony 建议getdealCategory()而不是getDealCategory()?

标签: phpsymfony

解决方案


您可以添加您的 formType 文件和控制器 addAction 的代码吗?

我认为您忘记了 DealType :

$resolver->setDefaults(array(
  'data_class' => 'App\Entity\Deal' 
));

希望这有帮助


推荐阅读