Note that there are some explanatory texts on larger screens.

plurals
  1. POForm Validation (Sym2) - Invalid parameter number: number of bound variables does not match number of tokens
    primarykey
    data
    text
    <p>i'm using Symfony2 + Doctrine 2</p> <p>In the validation of a dynamic form gives me this error and do not understand why. Only get error when I add one or more 'conocimiento' (Tags) to the class 'Recurso'</p> <p>I present here the corresponding classes</p> <pre><code>class Recurso { ... /** * @var TheWire\PersonaBundle\Entity\Rec_Conocimiento $conocimiento *, * @ORM\OneToMany(targetEntity="TheWire\PersonaBundle\Entity\Rec_Conocimiento", mappedBy="recurso", cascade={"all"}, orphanRemoval="true") */ private $conocimiento; ... public function __construct() { $this-&gt;conocimiento = new \Doctrine\Common\Collections\ArrayCollection(); } .... /** * Set conocimiento * * @param \TheWire\PersonaBundle\Entity\Rec_Conocimiento $conocimiento */ public function setConocimiento($conocimiento) { $this-&gt;conocimiento = $conocimiento; foreach ($conocimiento as $con){ $con-&gt;setRecurso($this); } } /** * Get conocimiento * * @return \Doctrine\Common\Collections\ArrayCollection */ public function getConocimiento() { return $this-&gt;conocimiento; } ..... </code></pre> <p>And</p> <pre><code>class Rec_Conocimiento { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * * @ORM\id * @ORM\ManyToOne(targetEntity="TheWire\PersonaBundle\Entity\Recurso", inversedBy="conocimiento") * @ORM\JoinColumn(name="recurso_id", referencedColumnName="id") */ private $recurso; /** * @var string $conocimiento * @ORM\Id * @ORM\ManyToOne(targetEntity="TheWire\PersonaBundle\Entity\Conocimiento") */ private $conocimiento; /** * @var smallint $nivel * * @ORM\Column(name="nivel", type="smallint") */ private $nivel; /** * Get id * * @return integer */ public function getId() { return $this-&gt;id; } /** * Set recurso * * @param \TheWire\PersonaBundle\Entity\Recurso $recurso */ public function setRecurso(\TheWire\PersonaBundle\Entity\Recurso $recurso) { $this-&gt;recurso = $recurso; } /** * Get recurso * * @return \TheWire\PersonaBundle\Entity\Recurso */ public function getRecurso() { return $this-&gt;recurso; } /** * Set conocimiento * * @param string $conocimiento */ public function setConocimiento(\TheWire\PersonaBundle\Entity\Conocimiento $conocimiento) { $this-&gt;conocimiento = $conocimiento; } /** * Get conocimiento * * @return string */ public function getConocimiento() { return $this-&gt;conocimiento; } /** * Set nivel * * @param smallint $nivel */ public function setNivel($nivel) { $this-&gt;nivel = $nivel; } /** * Get nivel * * @return smallint */ public function getNivel() { return $this-&gt;nivel; } ... </code></pre> <p>And class TheWire\PersonaBundle\Entity\Conocimiento is only $id and $name (Tags)</p> <p>I created the form:</p> <pre><code>class RecursoAddType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder -&gt;add('conocimiento', 'collection', array( 'required' =&gt; false, 'type' =&gt; new ConocimientoAddType(), 'allow_add' =&gt; true, 'allow_delete' =&gt; true, 'prototype' =&gt; true, // Post update 'by_reference' =&gt; false, )) ; } </code></pre> <p>and</p> <pre><code>class ConocimientoAddType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder -&gt;add('conocimiento', 'entity', array( 'required' =&gt; false, 'class' =&gt; 'TheWire\\PersonaBundle\\Entity\\Conocimiento', 'empty_value' =&gt; 'Selecciona un conocimiento', 'multiple' =&gt; false, 'query_builder' =&gt; function(EntityRepository $repositorio) { return $repositorio-&gt;createQueryBuilder('con')-&gt;leftjoin('con.bloque', 'bloque') -&gt;orderBy('bloque.descripcion, con.descripcion'); }, )) -&gt;add('nivel', null,array('required' =&gt; false, 'label' =&gt; 'Nivel: ')) ; } </code></pre> <p>I created in the controller normally, with a entity in the db and pass to Twig</p> <pre><code>$recurso = $em-&gt;getRepository('PersonaBundle:Recurso')-&gt;findOneBy(array('id' =&gt; $id)); $formularioEditarRecurso = $this-&gt;createForm(new RecursoAddType(), $recurso); </code></pre> <p>I show the form and use jquery to add more fields dynamically</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { function add() { var collectionHolder = $('#thewire_personabundle_recursoaddtype_conocimiento'); var prototype = collectionHolder.attr('data-prototype'); form = prototype.replace(/\$\$name\$\$/g, collectionHolder.children().length); collectionHolder.append(form); } $(".record_actions").delegate("a.jslink", "click", function(event){ event.preventDefault(); add(); }); }); &lt;/script&gt; </code></pre> <p>When valid form:</p> <pre><code>if ($request-&gt;getMethod() == 'POST') { $formularioEditarRecurso-&gt;bindRequest($request); if ($formularioEditarRecurso-&gt;isValid()) { $em-&gt;persist($recurso); $em-&gt;flush(); return $this-&gt;redirect($this-&gt;generateUrl('AdminPeticionVer', array('id' =&gt; $recurso-&gt;getPeticion()-&gt;getId()))); } } </code></pre> <p>Get the error:</p> <blockquote> <p>SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens</p> </blockquote> <p>I guess this error is to send more tags of which was</p> <p>how I can prevent this error? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload