我有生以来第一次使用 SonataAdminBundle,但遇到了一些问题。
起初,我有一个 PageBundle,它有一个Page和一个Author实体。然后我开始使用 SonataAdminBundle 并使用ssonata_type_model来很好地显示Authora 的 s Page:
// ...
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')
;
}
但后来我发现了 SonataUserBundle。我开始使用它,当我终于让它工作时,我认为使用这个User
实体而不是AuthorPageBundle 中的实体会很好。为了使这成为可能,我使用了文档在
“如何定义与抽象类和接口的关系”中讨论的技术。
这有效,但不适用于 SonataAdminBundle。似乎 the
sonata_type_model不能与 the 一起使用ResolveTargetEntityListener,我无法使其正常工作。
PagePageBundle中的相关实体代码:
namespace Wj\PageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table
* @ORM\Entity
* @ORM\HasLifeCycleCallbacks
*/
class Page
{
/**
* @var integer $authorId
*
* @ORM\ManyToOne(targetEntity="Wj\PageBundle\Model\AuthorInterface")
*/
private $author;
}
Wj\PageBundle\Model\AuthorInterface:_
namespace Wj\PageBundle\Model;
interface AuthorInterface
{
public function getId();
}
User以及UserBundle 中的实体:
namespace Wj\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser;
use Wj\PageBundle\Model\AuthorInterface;
use Doctrine\ORM\Mapping as 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()
{
return $this->getFirstName().' '.$this->getLastName();
}
}
FormMapper配置和我上面贴的一样。
如何将 ResolveTargetEntityListener 技术与 SonataAdminBundle 和他的 结合使用sonata_type_model?