Forms zend2插入到集合/数据库中
我对zf2和doctryne中的集合有一些问题 问题:我添加了一些客户端,需要一些multiselect 客户Forms zend2插入到集合/数据库中,forms,collections,insert,doctrine-orm,zend-framework2,Forms,Collections,Insert,Doctrine Orm,Zend Framework2,我对zf2和doctryne中的集合有一些问题 问题:我添加了一些客户端,需要一些multiselect 客户 /** * @ORM\MappedSuperclass */ class Client { ... /** * @ORM\ManyToOne(targetEntity="\Module\Model\Job") * @ORM\JoinColumn(name="job_id", referencedColumnName="id") */ protected $job; /** *
/**
* @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();
}
光学性
/**
* @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;
}
购买的模型有getter和setter,在客户端模型中有:
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;
}
表格:
在此之后,我需要有1行的客户端和1+行的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'
)
));