0
當我嘗試創建主義自參照關係ZF2形式,我得到主義錯誤Method "Status::getName" is not callable
ZF2表格/學說多對多自我參照關係
下面以我的實體我YAML配置:
Status:
type: entity
table: status
fields:
id:
id: true
type: integer
generator:
strategy: AUTO
options:
unsigned: true
name:
type: string
length: 255
manyToMany:
workflow:
targetEntity: Status
joinTable:
name: status_workflow
joinColumns:
statusId:
referencedColumnName: id
inverseJoinColumns:
nextStatusId:
referencedColumnName: id
和形式
class WorkflowForm extends Form
{
public function init()
{
$this->setName('workflow');
$this->add([
'name' => 'workflow',
'type' => WorkflowFieldset::class,
'options' => [
'use_as_base_fieldset' => true,
],
]);
}
}
和字段集
class WorkflowFieldset extends Fieldset ObjectManagerAwareInterface
{
use ProvidesObjectManager;
public function init()
{
$this->setName('workflow');
$this->add([
'name' => 'id',
'options' => [
'label' => 'Status name'
],
]);
$this->add([
'name' => 'workflow',
'type' => ObjectSelect::class,
'attributes' => [
'multiple' => true,
],
'options' => [
'object_manager' => $this->getObjectManager(),
'target_class' => Status::class,
'property' => 'name',
],
]);
}
}
和行動
public function workflowEditAction()
{
$sm = $this->getServiceLocator();
$fm = $sm->get('FormElementManager');
$om = $sm->get('Doctrine\ORM\EntityManager');
$form = $fm->get(WorkflowForm::class);
//$workflow = $om->getRepository(Status::class)->getStatusesByEntityId($route->getParam('id'));
//$form->bind($workflow);
return new ViewModel([
'form' => $form,
]);
}
最後,我希望得到這樣的
對不起這麼多的代碼沒有膨脹,甚至更多,我沒有表現出Hidrator,工廠和模板。
非常感謝大家的幫助。