我在zf2和doctryne中遇到了一些问题。
问题:我添加了一些客户端,需要一些多选。
ClientEntity
/**
* @ORM\MappedSuperclass
*/
class Client {
...
/**
* @ORM\ManyToOne(targetEntity="\Module\Model\Job")
* @ORM\JoinColumn(name="job_id", referencedColumnName="id")
*/
protected $job;
/**
* @ORM\OneToMany(targetEntity="SomeOption", mappedBy="job", cascade= {"persist", "remove"})
* */
protected $someOption;
...
public function __construct() {
$this->someOption= new ArrayCollection();
}
OptionEntity
/**
* @ORM\MappedSuperclass
*/
class SomeOption{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="\Module\Model\Client")
* @ORM\JoinColumn(name="job_id", referencedColumnName="id")
* */
protected $job;
/**
* @ORM\Column(type="string", nullable=false)
*/
protected $option;
}
Bought模型有getter和setter,在Client模型中有:
public function addSomeOption(Collection $options) {
foreach ($options as $option) {
$option->setJob($this);
$this->someOption->add($option);
}
return $this;
}
public function removeSomeOption(Collection $options) {
foreach ($options as $option) {
$option->setJob(null);
$this->someOption->removeElement($option);
}
return $this;
}
public function getSomeOption() {
return $this->someOption;
}
形式:
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'someOption',
'attributes' => array(
'id' => 'someOption',
),
'options' => array(
'label' => 'Rozliczenie',
'value_options' => array(
array('value' => '1r', 'label' => '1/rok'),
array('value' => '1m', 'label' => '1/miesiąc'),
array('value' => '1w', 'label' => '1/tydzień'),
array('value' => '1d', 'label' => '1/dzień'),
),
),
'attributes' => array(
'class' => 'span12 settlement chosen',
'multiple' => 'multiple'
)
));
在此之后我需要1行客户端和1+行someOption,可能有任何帮助修复代码?还是会解释我犯了什么错误。