Thursday, 15 July 2010

doctrine2 - Dynamic relationship and the SonataAdminBundle -



doctrine2 - Dynamic relationship and the SonataAdminBundle -

i utilize sonataadminbundle first time in life , have problems it.

at first, had pagebundle has page , author entity. started using sonataadminbundle , used sonata_type_model nicely display authors of page:

class="lang-php prettyprint-override">// ... protected function configureformfields(formmapper $mapper) { $mapper ->add('title') ->add('slug', null, array('required' => false)) ->add('published', null, array( 'label' => 'publish', 'required' => false, )) ->add('author', 'sonata_type_model') ->add('content') ; }

but discovered sonatauserbundle. started using , when working thought nice create utilize of user entity, instead of author entity in pagebundle. create possible, used technique documentation talks in "how define relationships abstract classes , interfaces".

this worked, not sonataadminbundle. seems sonata_type_model doesn't work resolvetargetentitylistener , can't create working.

the relevant page entity code in pagebundle:

class="lang-php prettyprint-override">namespace wj\pagebundle\entity; utilize doctrine\orm\mapping orm; /** * @orm\table * @orm\entity * @orm\haslifecyclecallbacks */ class page { /** * @var integer $authorid * * @orm\manytoone(targetentity="wj\pagebundle\model\authorinterface") */ private $author; }

the wj\pagebundle\model\authorinterface:

class="lang-php prettyprint-override">namespace wj\pagebundle\model; interface authorinterface { public function getid(); }

and user entity in userbundle:

class="lang-php prettyprint-override">namespace wj\userbundle\entity; utilize sonata\userbundle\entity\baseuser; utilize wj\pagebundle\model\authorinterface; utilize doctrine\orm\mapping orm; /** * @orm\entity * @orm\table(name="fos_user") */ class user extends baseuser implements authorinterface { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */ protected $id; public function __tostring() { homecoming $this->getfirstname().' '.$this->getlastname(); } }

the formmapper configuration same posted above.

how can utilize resolvetargetentitylistener technique in combination sonataadminbundle , sonata_type_model?

doctrine2 symfony-2.1 symfony-sonata sonata-admin

No comments:

Post a Comment