我有一個關於使用ZF2的Zend\Form
Doctrine ORM的類表繼承(CTI)的問題。在我們的系統中,每個用戶可以有多個角色,這些角色是通過班級表繼承方案定義的,以便我們可以定義角色特定的個人資料字段(即:「年級」僅適用於學生賬戶)。爲構建此,有一個Account
實體與一對多關聯Account\Role
(CTI與「基地」類):Zend Form Element Collection包含來自Doctrine Class表繼承的元素嗎?
<?php
namespace CdliPortal\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="account")
*/
class Account implements AccountInterface
{
// Other Fields Omitted
/**
* @ORM\OneToMany(targetEntity="CdliPortal\Entity\Account\Role", mappedBy="account", cascade={"ALL"})
*/
protected $roles;
}
我已經設置了一個Zend\Form
實例結合的Account
實體(我跟着example from the DoctrineModule
documentation ),並且一切似乎都在工作A-OK ...除了CTI收藏。在我的窗體對象我添加Zend\Form\Element\Collection
成員:
$roles = $user->getRoles();
if (count($roles) > 0) {
$formAccount->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'roles',
'options' => array(
'count' => count($roles),
'target_element' => $this->serviceLocator->get('cdliportal_form_account_role'),
),
));
}
然而,正如你可以在上面看到,當設置了roles
領域的target_element
(在這種情況下,一個字段)在集合級別指定,這意味着收集必須統一。對於上述情況,我需要能夠爲集合中的每個元素分別指定target_element
,具體取決於它所代表的CTI的哪一個成員。
任何想法如何,我會的方式,將仍然允許集合中的元素實現這一/諮詢時,我綁定帳號對象自動填充?