0

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.

Chiraq
  • 9
  • 1
  • 4
  • 1
    looks like you use a custom form template? (form/FormType.php.twig) anyway we need more code. – Frank B Nov 22 '15 at 04:43

1 Answers1

2

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!

Community
  • 1
  • 1
cezar
  • 11,616
  • 6
  • 48
  • 84
  • 1
    You can remove controller or overwrite it with php app/console generate:doctrine:crud --overwrite – ericksho Jan 12 '16 at 14:12