[英]Twig_Error_Runtime on symfony2
I'm currently learning Symfony2 and I'm stuck on the forms. 我目前正在学习Symfony2,但仍停留在表格上。 To be more specific, I try to set up a system of comment on an entity announcement. 更具体地说,我尝试建立一个关于实体公告的评论系统。
Unfortunately, when creating the commentaireType.php, using the php app/console doctrine:generate:form OCPlatformBundle:Commentaires I have an error message is this: 不幸的是,在创建commentaireType.php时,使用php应用程序/控制台doctrine:generate:form OCPlatformBundle:Commentaires,我收到一条错误消息是:
[Twig_Error_Runtime] Key "advert" for array with keys "id, auteur, contenu, date, ip" does not exist in "form/FormType.php.twig" at line 29
I noticed that by removing the ManyToOne relation of the entity that I tie, I no longer have the error message. 我注意到,通过删除我绑定的实体的ManyToOne关系,我不再收到错误消息。
/**
* @ORM\ManyToOne(targetEntity="OC\PlatformBundle\Entity\Advert", inversedBy="commentaires")
* @ORM\JoinColumn(nullable=false)
*/
private $advert;
Someone would have a solution to my problem? 有人可以解决我的问题吗? Thank you in advance ! 先感谢您 !
Chiraq. Chiraq。
The solution for your problem lies in the file FormType.php.twig
under the path: 您的问题的解决方案在路径下的文件FormType.php.twig
:
vendor/sensio/generator-bundle/Resources/skeleton/form/FormType.php.twig
on the line 29: 在第29行:
{%- if fields_mapping[field]['type'] in ['date', 'time', 'datetime'] %}
Change this to: 更改为:
{%- if fields_mapping[field] is defined and fields_mapping[field]['type'] in ['date', 'time', 'datetime'] %}
and rerun the command. 并重新运行该命令。 Eventually remove the controller that has been previously created. 最终删除先前创建的控制器。
Here are another useful links: 这是另一个有用的链接:
Generating forms with Symfony 2.8 throws a Twig_Error_Runtime 使用Symfony 2.8生成表单会引发Twig_Error_Runtime
https://github.com/sensiolabs/SensioGeneratorBundle/pull/431 https://github.com/sensiolabs/SensioGeneratorBundle/pull/431
https://github.com/sensiolabs/SensioGeneratorBundle/issues/443 https://github.com/sensiolabs/SensioGeneratorBundle/issues/443
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.