0
大家早上好!是一種形式。symfony2中的複選框字段
類ReleasesType:
$builder
->add('doid', 'text')
->add('dourl', 'text')
->add('artists', 'entity', array(
'class' => 'MReleaseCoreBundle:Artists',
'property' => 'name',
'expanded' => true ,
'multiple' => true
));
Сonnection與他們一到多:
級 '藝術家':
/**
* @ORM\OneToMany(targetEntity="ReleasesArtists" , mappedBy="artists" , cascade={"all"})
* */
private $da;
public function __construct() {
$this->da = new \Doctrine\Common\Collections\ArrayCollection();
}
班 'ReleasesArtists':
/**
* @ORM\ManyToOne(targetEntity="Releases", inversedBy="da")
* @ORM\JoinColumn(name="releases_id", referencedColumnName="id")
* */
private $releases;
/**
* @ORM\ManyToOne(targetEntity="Artists", inversedBy="da")
* @ORM\JoinColumn(name="artists_id", referencedColumnName="id")
* */
private $artists;
當然實體「發佈」:
/**
* @ORM\OneToMany(targetEntity="ReleasesArtists" , mappedBy="releases", cascade={"all"} , orphanRemoval=true)
*/
private $da;
public function getArtists() {
$artists = new ArrayCollection();
foreach($this->da as $p) {
$artists[] = $p->getArtists()->getName();
}
return $artists;
}
public function addDa($da) {
$this->da[] = $da;
}
public function setArtists($artists) {
foreach($artists as $p) {
$po = new \MRelease\CoreBundle\Entity\ReleasesArtists();
$po->setReleases($this);
$po->setArtists($p);
$this->addDa($po);
}
}
連接正常工作,所有輸出。但不「檢查」。可能是什麼問題? 謝謝!
我的方法:
– Konstantin@Konstantin:等等?我聽不懂你在說什麼。工作中?不工作?有什麼問題?請幫我理解:P – DonCallisto
英文不好:) 找出問題所在。 Getter不需要顯示標題是: $ artists [] = $ p-> getArtists() - > getName(); 取代 $藝術家[] = $ p-> getArtists(); – Konstantin