bonsoir les amis
je suis débutant dans ce fameux framework, je cherche depuis une semaine comment corriger un bug, mais en vain.
le bug consiste dans l'imbriquation d'un formulaire de type collection dans un autre
le message d'erreur apparait :
ContextErrorException: Warning: spl_object_hash() expects parameter 1 to be object, array given in C:\wamp\www\Kechtrip\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php line 1375
je mets à votre disposition le code source :
entite produit :
<?php
namespace Gestionloisirs\BackBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Produit
*
* @ORM\Table(name="sip_produit")
* @ORM\Entity(repositoryClass="Gestionloisirs\BackBundle\Entity\ProduitRepository")
*/
class Produit
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="ref", type="string", length=255, nullable=true)
*/
private $ref;
/**
* @var boolean
*
* @ORM\Column(name="home", type="boolean", nullable=true)
*/
private $home;
/**
* @var string
*
* @ORM\Column(name="adresse", type="string", length=255, nullable=true)
*/
private $adresse;
/**
* @var string
*
* @ORM\Column(name="code_postale", type="string", length=255, nullable=true)
*/
private $codePostale;
/**
* @var string
*
* @ORM\Column(name="ville", type="string", length=255, nullable=true)
*/
private $ville;
/**
* @var \DateTime
*
* @ORM\Column(name="date_ajout", type="date", nullable=true)
*/
private $dateAjout;
/**
* @var boolean
*
* @ORM\Column(name="click", type="boolean", nullable=true)
*/
private $click;
/**
* @var text
*
* @ORM\Column(name="property", type="text", nullable=true)
*/
private $property;
/**
* @var text
*
* @ORM\Column(name="property_info", type="text", nullable=true)
*/
private $propertyInfo;
/**
* @var text
*
* @ORM\Column(name="position", type="text", nullable=true)
*/
private $position;
/**
* @var boolean
*
* @ORM\Column(name="etat", type="boolean", nullable=true)
*/
private $etat;
/**
* @var boolean
*
* @ORM\Column(name="rang", type="boolean", nullable=true)
*/
private $rang;
/**
* @ORM\ManyToOne(targetEntity="Proprietaire")
*/
private $proprietaire;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set ref
*
* @param string $ref
* @return Produit
*/
public function setRef($ref)
{
$this->ref = $ref;
return $this;
}
/**
* Get ref
*
* @return string
*/
public function getRef()
{
return $this->ref;
}
/**
* Set home
*
* @param boolean $home
* @return Produit
*/
public function setHome($home)
{
$this->home = $home;
return $this;
}
/**
* Get home
*
* @return boolean
*/
public function getHome()
{
return $this->home;
}
/**
* Set adresse
*
* @param string $adresse
* @return Produit
*/
public function setAdresse($adresse)
{
$this->adresse = $adresse;
return $this;
}
/**
* Get adresse
*
* @return string
*/
public function getAdresse()
{
return $this->adresse;
}
/**
* Set codePostale
*
* @param string $codePostale
* @return Produit
*/
public function setCodePostale($codePostale)
{
$this->codePostale = $codePostale;
return $this;
}
/**
* Get codePostale
*
* @return string
*/
public function getCodePostale()
{
return $this->codePostale;
}
/**
* Set ville
*
* @param string $ville
* @return Produit
*/
public function setVille($ville)
{
$this->ville = $ville;
return $this;
}
/**
* Get ville
*
* @return string
*/
public function getVille()
{
return $this->ville;
}
/**
* Set dateAjout
*
* @param \DateTime $dateAjout
* @return Produit
*/
public function setDateAjout($dateAjout)
{
$this->dateAjout = $dateAjout;
return $this;
}
/**
* Get dateAjout
*
* @return \DateTime
*/
public function getDateAjout()
{
return $this->dateAjout;
}
/**
* Set click
*
* @param boolean $click
* @return Produit
*/
public function setClick($click)
{
$this->click = $click;
return $this;
}
/**
* Get click
*
* @return boolean
*/
public function getClick()
{
return $this->click;
}
/**
* Set property
*
* @param string $property
* @return Produit
*/
public function setProperty($property)
{
$this->property = $property;
return $this;
}
/**
* Get property
*
* @return string
*/
public function getProperty()
{
return $this->property;
}
/**
* Set propertyInfo
*
* @param string $propertyInfo
* @return Produit
*/
public function setPropertyInfo($propertyInfo)
{
$this->propertyInfo = $propertyInfo;
return $this;
}
/**
* Get propertyInfo
*
* @return string
*/
public function getPropertyInfo()
{
return $this->propertyInfo;
}
/**
* Set position
*
* @param string $position
* @return Produit
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* @return string
*/
public function getPosition()
{
return $this->position;
}
/**
* Set etat
*
* @param boolean $etat
* @return Produit
*/
public function setEtat($etat)
{
$this->etat = $etat;
return $this;
}
/**
* Get etat
*
* @return boolean
*/
public function getEtat()
{
return $this->etat;
}
/**
* Set rang
*
* @param boolean $rang
* @return Produit
*/
public function setRang($rang)
{
$this->rang = $rang;
return $this;
}
/**
* Get rang
*
* @return boolean
*/
public function getRang()
{
return $this->rang;
}
/**
* Set proprietaire
*
* @param \Gestionloisirs\BackBundle\Entity\Proprietaire $proprietaire
* @return Produit
*/
public function setProprietaire(\Gestionloisirs\BackBundle\Entity\Proprietaire $proprietaire = null)
{
$this->proprietaire = $proprietaire;
return $this;
}
/**
* Get proprietaire
*
* @return \Gestionloisirs\BackBundle\Entity\Proprietaire
*/
public function getProprietaire()
{
return $this->proprietaire;
}
}
entite produitlangue :
<?php
namespace Gestionloisirs\BackBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Produitlangue
*
* @ORM\Table(name="sip_produit_langue")
* @ORM\Entity(repositoryClass="Gestionloisirs\BackBundle\Entity\ProduitlangueRepository")
*/
class Produitlangue
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="alias", type="string", length=255, nullable=true)
*/
private $alias;
/**
* @var string
*
* @ORM\Column(name="ptitre", type="string", length=255, nullable=true)
*/
private $ptitre;
/**
* @var string
*
* @ORM\Column(name="pwindow", type="string", length=255, nullable=true)
*/
private $pwindow;
/**
* @var text
*
* @ORM\Column(name="pdescr", type="text", nullable=true)
*/
private $pdescr;
/**
* @var string
*
* @ORM\Column(name="pkey", type="string", length=255, nullable=true)
*/
private $pkey;
/**
* @var string
*
* @ORM\Column(name="ph1", type="string", length=255, nullable=true)
*/
private $ph1;
/**
* @var text
*
* @ORM\Column(name="pcontenu", type="text", nullable=true)
*/
private $pcontenu;
/**
* @ORM\ManyToOne(targetEntity="Langue")
*/
private $langue;
/**
* @ORM\OneToMany(targetEntity="Produitlangueproduit", mappedBy="produitlangue"))
*/
private $produitlangueproduit;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set alias
*
* @param string $alias
* @return Produitlangue
*/
public function setAlias($alias)
{
$this->alias = $alias;
return $this;
}
/**
* Get alias
*
* @return string
*/
public function getAlias()
{
return $this->alias;
}
/**
* Set ptitre
*
* @param string $ptitre
* @return Produitlangue
*/
public function setPtitre($ptitre)
{
$this->ptitre = $ptitre;
return $this;
}
/**
* Get ptitre
*
* @return string
*/
public function getPtitre()
{
return $this->ptitre;
}
/**
* Set pwindow
*
* @param string $pwindow
* @return Produitlangue
*/
public function setPwindow($pwindow)
{
$this->pwindow = $pwindow;
return $this;
}
/**
* Get pwindow
*
* @return string
*/
public function getPwindow()
{
return $this->pwindow;
}
/**
* Set pdescr
*
* @param string $pdescr
* @return Produitlangue
*/
public function setPdescr($pdescr)
{
$this->pdescr = $pdescr;
return $this;
}
/**
* Get pdescr
*
* @return string
*/
public function getPdescr()
{
return $this->pdescr;
}
/**
* Set pkey
*
* @param string $pkey
* @return Produitlangue
*/
public function setPkey($pkey)
{
$this->pkey = $pkey;
return $this;
}
/**
* Get pkey
*
* @return string
*/
public function getPkey()
{
return $this->pkey;
}
/**
* Set ph1
*
* @param string $ph1
* @return Produitlangue
*/
public function setPh1($ph1)
{
$this->ph1 = $ph1;
return $this;
}
/**
* Get ph1
*
* @return string
*/
public function getPh1()
{
return $this->ph1;
}
/**
* Set pcontenu
*
* @param string $pcontenu
* @return Produitlangue
*/
public function setPcontenu($pcontenu)
{
$this->pcontenu = $pcontenu;
return $this;
}
/**
* Get pcontenu
*
* @return string
*/
public function getPcontenu()
{
return $this->pcontenu;
}
/**
* Set langue
*
* @param \Gestionloisirs\BackBundle\Entity\Langue $langue
* @return Produitlangue
*/
public function setLangue(\Gestionloisirs\BackBundle\Entity\Langue $langue = null)
{
$this->langue = $langue;
return $this;
}
/**
* Get langue
*
* @return \Gestionloisirs\BackBundle\Entity\Langue
*/
public function getLangue()
{
return $this->langue;
}
/**
* Constructor
*/
public function __construct()
{
$this->produitlangueproduit = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add produitlangueproduit
*
* @param \Gestionloisirs\BackBundle\Entity\Produitlangueproduit $produitlangueproduit
* @return Produitlangue
*/
public function addProduitlangueproduit(\Gestionloisirs\BackBundle\Entity\Produitlangueproduit $produitlangueproduit)
{
$this->produitlangueproduit[] = $produitlangueproduit;
return $this;
}
/**
* Remove produitlangueproduit
*
* @param \Gestionloisirs\BackBundle\Entity\Produitlangueproduit $produitlangueproduit
*/
public function removeProduitlangueproduit(\Gestionloisirs\BackBundle\Entity\Produitlangueproduit $produitlangueproduit)
{
$this->produitlangueproduit->removeElement($produitlangueproduit);
}
/**
* Get produitlangueproduit
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProduitlangueproduit()
{
return $this->produitlangueproduit;
}
/**
* Set produitlangueproduit
*
* @param \Gestionloisirs\BackBundle\Entity\Produitlangueproduit $produitlangueproduit
* @return Produitlangue
*/
public function setProduitlangueproduit(\Gestionloisirs\BackBundle\Entity\Produitlangueproduit $produitlangueproduit)
{
$this->produitlangueproduit = $produitlangueproduit;
return $this;
}
}
entite produitlangueproduit:
<?php
namespace Gestionloisirs\BackBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Produitlangueproduit
*
* @ORM\Table(name="sip_produitlangueproduit")
* @ORM\Entity(repositoryClass="Gestionloisirs\BackBundle\Entity\ProduitlangueRepository")
*/
class Produitlangueproduit
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Produitlangue", inversedBy="produitlangueproduits", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $produitlangue;
/**
* @ORM\ManyToOne(targetEntity="Produit", cascade={"persist"})
*/
private $produit;
/**
* Add produitlangue
*
* @param \Gestionloisirs\BackBundle\Entity\Produitlangue $produitlangue
*/
public function addProduitlangue(\Gestionloisirs\BackBundle\Entity\Produitlangue $produitlangue)
{
$this->produitlangue[] = $produitlangue;
$produitlangue->setProduitlangueproduit($this);
}
/**
* Get produitlangue
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProduitlangue()
{
return $this->produitlangue;
}
public function setProduitlangue(array $produitlangue)
{
$this->produitlangue = new \Doctrine\Common\Collections\ArrayCollection($produitlangue);
foreach ($produitlangue as $pl){
$pl->setProduitlangueproduit($this);
}
}
/**
* Remove produitlangue
*
* @param \Gestionloisirs\BackBundle\Entity\Produitlangue $produitlangue
*/
public function removeProduitlangue(\Gestionloisirs\BackBundle\Entity\Produitlangue $produitlangue)
{
$this->produitlangue->removeElement($produitlangue);
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set produit
*
* @param \Gestionloisirs\BackBundle\Entity\Produit $produit
* @return Produitlangueproduit
*/
public function setProduit(\Gestionloisirs\BackBundle\Entity\Produit $produit)
{
$this->produit = $produit;
return $this;
}
/**
* Get produit
*
* @return \Gestionloisirs\BackBundle\Entity\Produit
*/
public function getProduit()
{
return $this->produit;
}
}
form produitlangue:
<?php
namespace Gestionloisirs\BackBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ProduitlangueForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('alias', 'text',array('required'=> false))
->add('ptitre', 'text',array('required'=> false))
->add('pwindow', 'text',array('required'=> false))
->add('pdescr', 'text',array('required'=> false))
->add('pkey', 'text',array('required'=> false))
->add('ph1', 'text',array('required'=> false))
->add('pcontenu', 'textarea',array('required'=> false));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Gestionloisirs\BackBundle\Entity\Produitlangue'
));
}
public function getName()
{
return 'produitlangue';
}
}
form produitlangueproduit
<?php
namespace Gestionloisirs\BackBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Gestionloisirs\BackBundle\Form\ProduitlangueForm;
use Gestionloisirs\BackBundle\Form\ProduitForm;
class ProduitlangueproduitForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('produit', new ProduitForm())
->add('produitlangue', 'collection', array('type' => new ProduitlangueForm(),
'allow_add' => true,
'prototype'=>true,
'by_reference' => false));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Gestionloisirs\BackBundle\Entity\Produitlangueproduit'
));
}
public function getName()
{
return 'produitlangueproduit';
}
}
mon controleur:
public function editerAction($id = NULL)
{
$em = $this->getDoctrine()->getManager();
$currentdate = new \DateTime('now');
if (isset($id))
{
$produitlangueproduit = $em->getRepository('GestionloisirsBackBundleroduitlangueproduit')->find($id);
}
else $produitlangueproduit = new Produitlangueproduit();
$query = $em->createQuery('SELECT l.titreLangue FROM GestionloisirsBackBundle:Langue l WHERE l.etat = :val');
$query->setParameter('val', '1');
$titrelangue = $query->getResult();
$query2 = $em->createQuery('SELECT COUNT(l.id) FROM GestionloisirsBackBundle:Langue l WHERE l.etat = :val');
$query2->setParameter('val', '1');
$count = $query2->getSingleScalarResult();
/*
for($i = 0; $i<$count ; $i++){
$val = "produitlangue".$i;
$$val = new Produitlangue();
$produitlangueproduit->addProduitlangue($$val);
}
*/
$val = new Produitlangue();
$produitlangueproduit->addProduitlangue($val);
$form = $this->createForm(new ProduitlangueproduitForm(), $produitlangueproduit);
$request = $this->getRequest();
if ($request->getMethod() == 'POST')
{
$form->bind($request);
if ($form->isValid())
{
$em->persist($produitlangueproduit);
$em->flush();
return $this->redirect($this->generateUrl('gestion_produits'));
}
}
return $this->render('GestionloisirsBackBundleroduitlangue:editer.html.twig',array(
'form' => $form->createView(),
'titreslangue' => $titrelangue
));
}
ma vue :
<form action="" method="post" {{ form_enctype(form) }}>
{{ form_errors(form) }}
{{ form_widget(form) }}
<input type="submit" />
</form>
Partager