Wenn ich versuche, ZF2 Formular mit Lehre Selbstreferenzierung Beziehung zu erstellen:ZF2 Form/Lehre ManyToMany Selbst Bezug Relation
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
und Form
class WorkflowForm extends Form
{
public function init()
{
$this->setName('workflow');
$this->add([
'name' => 'workflow',
'type' => WorkflowFieldset::class,
'options' => [
'use_as_base_fieldset' => true,
],
]);
}
}
und fieldset
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',
],
]);
}
}
und Aktion
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,
]);
}
Schließlich möchte ich so viel Code so etwas wie dieses
Leider erhalten nicht noch mehr aufzublasen, ich nicht zeigen Hidrator, Fabrik und Vorlage .
Vielen Dank im Voraus für Ihre Hilfe.