简体   繁体   中英

Twig_Error_Runtime on symfony2

I'm currently learning Symfony2 and I'm stuck on the forms. 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:

  [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.

 /**
 * @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.

The solution for your problem lies in the file FormType.php.twig under the path:

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

on the line 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

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

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

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM