symfony2上的Twig_Error_Runtime

时间:2015-11-22 02:58:40

标签: php symfony

我正在学习Symfony2,而且我被困在表格上。更具体地说,我尝试建立一个对实体公告发表评论的系统。

不幸的是,在创建commentaireType.php时,使用php app / console 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

我注意到通过删除我绑定的实体的ManyToOne关系,我不再有错误消息。

 /**
 * @ORM\ManyToOne(targetEntity="OC\PlatformBundle\Entity\Advert", inversedBy="commentaires")
 * @ORM\JoinColumn(nullable=false)
 */
private $advert;

有人可以解决我的问题吗?提前谢谢!

Chiraq。

1 个答案:

答案 0 :(得分:2)

问题的解决方案位于路径下的文件FormType.php.twig

vendor/sensio/generator-bundle/Resources/skeleton/form/FormType.php.twig

第29行:

{%- if fields_mapping[field]['type'] in ['date', 'time', 'datetime'] %}

将其更改为:

{%- if fields_mapping[field] is defined and fields_mapping[field]['type'] in ['date', 'time', 'datetime'] %}

并重新运行该命令。最终删除先前创建的控制器。

以下是另一个有用的链接:

Generating forms with Symfony 2.8 throws a Twig_Error_Runtime

https://github.com/sensiolabs/SensioGeneratorBundle/pull/431

https://github.com/sensiolabs/SensioGeneratorBundle/issues/443

祝你好运!