dimanche 19 avril 2015

Warning: spl_object_hash() expects parameter 1 to be object, array given Collection forms

i created a collection form for a CV for each user of the web application and each CV contain many Experiences, Languages, Formation, Competance!


and add a Jquery code to use the data-prototype in the collection form so the user can add multiple experiences and formation etc... to his cv


for now everything is okay my form is well shown but the problem when is submit!


i get this error: Warning: spl_object_hash() expects parameter 1 to be object, array given


here is my yml for doctrine:


cv.orm.yml:



cyn\UserBundle\Entity\Cv:
type: entity
table: cv
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
expenmois:
type: integer
divers:
type: text
oneToMany:
experience:
targetEntity: Experience
mappedBy: cv
cascade: ["persist", "merge"]
formation:
targetEntity: Formation
mappedBy: cv
cascade: ["persist", "merge"]
competance:
targetEntity: Competance
mappedBy: cv
cascade: ["persist", "merge"]
langue:
targetEntity: Langue
mappedBy: cv
cascade: ["persist", "merge"]


Experience.orm.yml:



cyn\UserBundle\Entity\Experience:
type: entity
table: experience
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
nom_societe:
type: string
length: 255
nullable: false
lieutravail:
type: string
length: 255
nullable: false
poste:
type: string
length: 255
nullable: false
datedebut:
type: date
datefin:
type: date
description:
type: text
manyToOne:
cv:
targetEntity: Cv
inversedBy: experience
joinColumn:
name: cv_id
referencedColumnName: id


formation.orm.yml:



cyn\UserBundle\Entity\Formation:
type: entity
table: formation
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
etablissement:
type: string
length: 255
nullable: false
datedebut:
type: date
datefin:
type: date
manyToOne:
cv:
targetEntity: Cv
inversedBy: formation
joinColumn:
name: cv_id
referencedColumnName: id


competance.orm.yml:



cyn\UserBundle\Entity\Competance:
type: entity
table: competance
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
domaine:
type: string
length: 255
details:
type: string
length: 255
manyToOne:
cv:
targetEntity: Cv
inversedBy: competance
joinColumn:
name: cv_id
referencedColumnName: id


langue.orm.yml



cyn\UserBundle\Entity\Langue:
type: entity
table: langue
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
langue:
type: string
length: 255
niveau:
type: string
length: 255
manyToOne:
cv:
targetEntity: Cv
inversedBy: langue
joinColumn:
name: cv_id
referencedColumnName: id


and this is my collection form type:



<?php

namespace cyn\UserBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use cyn\UserBundle\Entity\Cv;
use cyn\UserBundle\Entity\Experience;
use cyn\UserBundle\Entity\Competance;
use cyn\UserBundle\Entity\Langue;
use cyn\UserBundle\Entity\Formation;

class CvType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{

$builder->add('expEnMois', 'text');
$builder->add('divers', 'textarea');
$builder->add('experience', 'collection',array(
'type'=> new ExperienceType(),
'allow_add'=>true,
'allow_delete' => true )
);


$builder->add('Enregistrer', 'submit');
}

public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'cyn\UserBundle\Entity\Cv',



);
}

public function getName()
{
return 'cv';
}
}


and this is my controller for add:



<?php

namespace cyn\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\Common\Collections\Collection;

use cyn\UserBundle\Form\Type\CvType;
use cyn\UserBundle\Entity\Cv;
use cyn\UserBundle\Entity\Competance;
use cyn\UserBundle\Entity\Langue;
use cyn\UserBundle\Entity\Experience;
use cyn\UserBundle\Entity\Formation;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class CvController extends Controller
{

public function addAction()
{
$cv = new Cv();
$exp = new Experience();
$exp->setCv($cv);

$form = $this->get('form.factory')->create(new CvType(), $cv);


$request = $this->getRequest();

if ('POST' === $request->getMethod()) {
$form->handleRequest($request);

if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();

$em->persist($cv);
$em->flush();

$this->get('session')->getFlashBag()->add('notice', 'Félicitations, votre cv a bien été enregistré.' );



}
}

return $this->render('cynUserBundle:Default:ajoutercv.html.twig', array(
'form' => $form->createView(),
));
}

}


my cv entity:



<?php

namespace cyn\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Cv
*/
class Cv
{
/**
* @var integer
*/
private $id;

/**
* @var integer
*/
private $expenmois;

/**
* @var string
*/
private $divers;

/**
* @var \Doctrine\Common\Collections\Collection
*/
private $experience;

/**
* @var \Doctrine\Common\Collections\Collection
*/
private $formation;

/**
* @var \Doctrine\Common\Collections\Collection
*/
private $competance;

/**
* @var \Doctrine\Common\Collections\Collection
*/
private $langue;

/**
* Constructor
*/
public function __construct()
{
$this->experience = new \Doctrine\Common\Collections\ArrayCollection();
$this->formation = new \Doctrine\Common\Collections\ArrayCollection();
$this->competance = new \Doctrine\Common\Collections\ArrayCollection();
$this->langue = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set expenmois
*
* @param integer $expenmois
* @return Cv
*/
public function setExpenmois($expenmois)
{
$this->expenmois = $expenmois;

return $this;
}

/**
* Get expenmois
*
* @return integer
*/
public function getExpenmois()
{
return $this->expenmois;
}

/**
* Set divers
*
* @param string $divers
* @return Cv
*/
public function setDivers($divers)
{
$this->divers = $divers;

return $this;
}

/**
* Get divers
*
* @return string
*/
public function getDivers()
{
return $this->divers;
}

/**
* Add experience
*
* @param \cyn\UserBundle\Entity\Experience $experience
* @return Cv
*/
public function addExperience(\cyn\UserBundle\Entity\Experience $experience)
{
$this->experience[] = $experience;

return $this;
}

/**
* Remove experience
*
* @param \cyn\UserBundle\Entity\Experience $experience
*/
public function removeExperience(\cyn\UserBundle\Entity\Experience $experience)
{
$this->experience->removeElement($experience);
}

/**
* Get experience
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getExperience()
{
return $this->experience;
}

/**
* Add formation
*
* @param \cyn\UserBundle\Entity\Formation $formation
* @return Cv
*/
public function addFormation(\cyn\UserBundle\Entity\Formation $formation)
{
$this->formation[] = $formation;

return $this;
}

/**
* Remove formation
*
* @param \cyn\UserBundle\Entity\Formation $formation
*/
public function removeFormation(\cyn\UserBundle\Entity\Formation $formation)
{
$this->formation->removeElement($formation);
}

/**
* Get formation
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFormation()
{
return $this->formation;
}

/**
* Add competance
*
* @param \cyn\UserBundle\Entity\Competance $competance
* @return Cv
*/
public function addCompetance(\cyn\UserBundle\Entity\Competance $competance)
{
$this->competance[] = $competance;

return $this;
}

/**
* Remove competance
*
* @param \cyn\UserBundle\Entity\Competance $competance
*/
public function removeCompetance(\cyn\UserBundle\Entity\Competance $competance)
{
$this->competance->removeElement($competance);
}

/**
* Get competance
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCompetance()
{
return $this->competance;
}

/**
* Add langue
*
* @param \cyn\UserBundle\Entity\Langue $langue
* @return Cv
*/
public function addLangue(\cyn\UserBundle\Entity\Langue $langue)
{
$this->langue[] = $langue;

return $this;
}

/**
* Remove langue
*
* @param \cyn\UserBundle\Entity\Langue $langue
*/
public function removeLangue(\cyn\UserBundle\Entity\Langue $langue)
{
$this->langue->removeElement($langue);
}

/**
* Get langue
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getLangue()
{
return $this->langue;
}
}


and here is one of my others entitys experience.php:



<?php

namespace cyn\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Experience
*/
class Experience
{
/**
* @var integer
*/
private $id;

/**
* @var string
*/
private $nom_societe;

/**
* @var string
*/
private $lieutravail;

/**
* @var string
*/
private $poste;

/**
* @var \DateTime
*/
private $datedebut;

/**
* @var \DateTime
*/
private $datefin;

/**
* @var string
*/
private $description;

/**
* @var \cyn\UserBundle\Entity\Cv
*/
private $cv;


/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set nom_societe
*
* @param string $nomSociete
* @return Experience
*/
public function setNomSociete($nomSociete)
{
$this->nom_societe = $nomSociete;

return $this;
}

/**
* Get nom_societe
*
* @return string
*/
public function getNomSociete()
{
return $this->nom_societe;
}

/**
* Set lieutravail
*
* @param string $lieutravail
* @return Experience
*/
public function setLieutravail($lieutravail)
{
$this->lieutravail = $lieutravail;

return $this;
}

/**
* Get lieutravail
*
* @return string
*/
public function getLieutravail()
{
return $this->lieutravail;
}

/**
* Set poste
*
* @param string $poste
* @return Experience
*/
public function setPoste($poste)
{
$this->poste = $poste;

return $this;
}

/**
* Get poste
*
* @return string
*/
public function getPoste()
{
return $this->poste;
}

/**
* Set datedebut
*
* @param \DateTime $datedebut
* @return Experience
*/
public function setDatedebut($datedebut)
{
$this->datedebut = $datedebut;

return $this;
}

/**
* Get datedebut
*
* @return \DateTime
*/
public function getDatedebut()
{
return $this->datedebut;
}

/**
* Set datefin
*
* @param \DateTime $datefin
* @return Experience
*/
public function setDatefin($datefin)
{
$this->datefin = $datefin;

return $this;
}

/**
* Get datefin
*
* @return \DateTime
*/
public function getDatefin()
{
return $this->datefin;
}

/**
* Set description
*
* @param string $description
* @return Experience
*/
public function setDescription($description)
{
$this->description = $description;

return $this;
}

/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* Set cv
*
* @param \cyn\UserBundle\Entity\Cv $cv
* @return Experience
*/
public function setCv(\cyn\UserBundle\Entity\Cv $cv = null)
{
$this->cv = $cv;

return $this;
}

/**
* Get cv
*
* @return \cyn\UserBundle\Entity\Cv
*/
public function getCv()
{
return $this->cv;
}
}


please help me i've been 1 week and i cannot solve this problem


Aucun commentaire:

Enregistrer un commentaire