我在谷歌上找到了所有主题,但没有得到解决方案。
我有这个错误:
给定类型为“PL\PlatformBundle\Entity\Module”、“Doctrine\Common\Collections\ArrayCollection”的预期参数
我想在列表中选择多个模块,但是当我单击保存时出现错误。
我的表格:
<?php
namespace PL\AppAccueilBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Doctrine\ORM\EntityRepository;
class AppAccueilModuleType extends AbstractType {
private $idCompany;
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$this->idCompany = $options['idCompany'];
$builder
->add('company', CollectionType::class, array(
'class' => 'PLUserBundle:Company',
'choice_label' => 'Name',
'multiple' => false
))
->remove('company')
->add('module', EntityType::class, array(
'class' => 'PLPlatformBundle:Module',
'choice_label' => function ($allChoices) {
if ($allChoices->getRef() != null)
return $allChoices->getRef() . ' - ' . $allChoices->getTitre() . " (" . $allChoices->getSupport()->getTitre() . ")";
else
return $allChoices->getTitre() . " (" . $allChoices->getSupport()->getTitre() . ")";
},
'multiple' => true,
'expanded' => false,
'query_builder' => function (EntityRepository $er) {
return $er->getModulesListForCompany($this->idCompany);
},
))
->add('save', SubmitType::class);;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(array(
'data_class' => 'PL\AppAccueilBundle\Entity\AppAccueilModule',
'idCompany' => null
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix() {
return 'pl_appaccueilbundle_appaccueilmodule';
}
}
我的实体:
<?php
namespace PL\PlatformBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use PL\AppAccueilBundle\Entity\ParcoursModule;
use PL\AppChallengeBundle\Entity\ChallengeModule;
use PL\UserBundle\Entity\Company;
use PL\UserBundle\Entity\Logo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Module
* @ORM\Table(name="pl_module")
* @ORM\Entity(repositoryClass="PL\PlatformBundle\Repositor\ModuleRepository")
*/
class Module {
/**
* @var int
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
* @ORM\Column(name="titre", type="string", length=255)
*/
private $titre;
/**
* @var string
* @ORM\Column(name="ref", type="string", length=255, nullable=true)
*/
private $ref;
/**
* @ORM\ManyToOne(targetEntity="PL\PlatformBundle\Entity\Support")
* @ORM\JoinColumn(nullable=false)
*/
private $support;
/**
* @ORM\ManyToOne(targetEntity="PL\PlatformBundle\Entity\Theme")
* @ORM\JoinColumn(nullable=false)
*/
private $theme;
/**
* @ORM\ManyToOne(targetEntity="PL\UserBundle\Entity\Company")
* @ORM\JoinColumn(nullable=false)
*/
private $company;
/**
* @ORM\OneToOne(targetEntity="PL\UserBundle\Entity\Logo", cascade="persist")
* @ORM\JoinTable(name="pl_logo")
* @Assert\Valid()
*/
private $logo;
/**
* @ORM\ManyToMany(targetEntity="PL\PlatformBundle\Entity\Document", cascade="persist")
* @ORM\JoinTable(name="pl_module_document")
*/
private $documents;
/**
* @ORM\ManyToMany(targetEntity="PL\PlatformBundle\Entity\ChasseZone", cascade="persist")
* @ORM\JoinTable(name="pl_module_chasse_zone")
*/
private $chasseZone;
/**
* @ORM\ManyToMany(targetEntity="PL\PlatformBundle\Entity\Question", cascade="persist")
* @ORM\JoinTable(name="pl_module_quiz")
* @ORM\OrderBy({"position" = "ASC"})
*/
private $question;
/**
* @var string
* @ORM\Column(name="code_iframe", type="string", length=4095, nullable=true)
*/
private $codeIframe;
/**
* @ORM\OneToOne(targetEntity="PL\PlatformBundle\Entity\ChasseImage", cascade="persist")
* @ORM\JoinTable(name="pl_module_chasse_image")
* @Assert\Valid()
*/
private $chasseImage;
/**
* @ORM\OneToMany(targetEntity="PL\AppAccueilBundle\Entity\ParcoursModule", mappedBy="module", cascade={"persist", "remove"}, orphanRemoval=TRUE)
*/
private $parcours;
/**
* @ORM\OneToMany(targetEntity="PL\AppChallengeBundle\Entity\ChallengeModule", mappedBy="module", cascade={"persist", "remove"}, orphanRemoval=TRUE)
*/
private $challenges;
/**
* Get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* Set titre
* @param string $titre
* @return module
*/
public function setTitre($titre) {
$this->titre = $titre;
return $this;
}
/**
* Get titre
* @return string
*/
public function getTitre() {
return $this->titre;
}
/**
* Set ref
* @param string $ref
* @return module
*/
public function setRef($ref) {
$this->ref = $ref;
return $this;
}
/**
* Get ref
* @return string
*/
public function getRef() {
return $this->ref;
}
/**
* Set support
* @param Support $support
* @return Module
*/
public function setSupport(Support $support) {
$this->support = $support;
return $this;
}
/**
* Get support
* @return Support
*/
public function getSupport() {
return $this->support;
}
/**
* Set theme
* @param Theme $theme
* @return Module
*/
public function setTheme(Theme $theme) {
$this->theme = $theme;
return $this;
}
/**
* Get theme
* @return Theme
*/
public function getTheme() {
return $this->theme;
}
/**
* Set company
*
* @param Company $company
* @return Module
*/
public function setCompany(Company $company) {
$this->company = $company;
return $this;
}
/**
* Get company
* @return Company
*/
public function getCompany() {
return $this->company;
}
/**
* Set logo
* @param Logo $logo
* @return Module
*/
public function setLogo(Logo $logo = null) {
$this->logo = $logo;
return $this;
}
/**
* Get logo
* @return Logo
*/
public function getLogo() {
return $this->logo;
}
/**
* Constructor
*/
public function __construct() {
$this->documents = new ArrayCollection();
$this->chasseZone = new ArrayCollection();
$this->question = new ArrayCollection();
$this->parcours = new ArrayCollection();
$this->challenges = new ArrayCollection();
}
/**
* Add document
* @param Document $document
* @return Module
*/
public function addDocument(Document $document) {
$this->documents[] = $document;
return $this;
}
/**
* Remove document
* @param Document $document
*/
public function removeDocument(Document $document) {
$this->documents->removeElement($document);
}
/**
* Get documents
* @return \Doctrine\Common\Collections\Collection
*/
public function getDocuments() {
return $this->documents;
}
/**
* Set codeIframe
* @param string $codeIframe
* @return Module
*/
public function setCodeIframe($codeIframe) {
$this->codeIframe = $codeIframe;
return $this;
}
/**
* Get codeIframe
* @return string
*/
public function getCodeIframe() {
return $this->codeIframe;
}
/**
* Set chasseImage
* @param ChasseImage $chasseImage
* @return Module
*/
public function setChasseImage(ChasseImage $chasseImage = null) {
$this->chasseImage = $chasseImage;
return $this;
}
/**
* Get chasseImage
* @return ChasseImage
*/
public function getChasseImage() {
return $this->chasseImage;
}
/**
* Remove chasseZone
* @param ChasseZone $ch
*/
public function removeChasseZone(ChasseZone $ch) {
$this->chasseZone->removeElement($ch);
}
/**
* Get chasseZone
* @return \Doctrine\Common\Collections\Collection
*/
public function getChasseZone() {
return $this->chasseZone;
}
/**
* Add chasseZone
* @param \PL\PlatformBundle\Entity\ChasseZone $chasseZone
* @return Module
*/
public function addChasseZone(ChasseZone $chasseZone) {
$this->chasseZone[] = $chasseZone;
return $this;
}
/**
* Get questions
* @return \Doctrine\Common\Collections\Collection
*/
public function getQuestions() {
return $this->question;
}
/**
* Add question
* @param \PL\PlatformBundle\Entity\Question $question
* @return Module
*/
public function addQuestion(Question $question) {
$this->question[] = $question;
return $this;
}
/**
* Remove question
* @param Question $question
*/
public function removeQuestion(Question $question) {
$this->question->removeElement($question);
}
/**
* Get parcours
* @return \Doctrine\Common\Collections\Collection
*/
public function getParcours() {
return $this->parcours;
}
/**
* Add parcours
* @param ParcoursModule $parcours
* @return Module
*/
public function addParcours(ParcoursModule $parcours) {
$this->parcours[] = $parcours;
$parcours->setModule($this);
return $this;
}
/**
* Remove parcours
* @param ParcoursModule $parcours
*/
public function removeParcours(ParcoursModule $parcours) {
$this->parcours->removeElement($parcours);
}
/**
* Get Challenges
* @return ArrayCollection
*/
public function getChallenges() {
return $this->challenges;
}
/**
* Add challenge module
* @param ChallengeModule $challenge
* @return Module
*/
public function addChallenge(ChallengeModule $challenge) {
$this->challenges[] = $challenge;
$challenge->setModule($this);
return $this;
}
/**
* Remove challenges module
* @param ChallengeModule $challenge
*/
public function removeChallenges(ChallengeModule $challenge) {
$this->challenges->removeElement($challenge);
}
}
认为