我在我的项目上使用SonataAdminBundle。我也安装了SonataUserBundle和FOSUserBundle。 当我尝试登录到管理面板时,访问已完成,但是当我尝试列出所有用户和组时,出现以下异常:
No metadata found for property `Sonata\UserBundle\Entity\BaseUser::$id`. Please make sure your Doctrine mapping is properly configured.
我的Sonata_admin.yml:
sonata_admin:
title: 'Staff.ma'
title_logo: bundles/sonataadmin/logo_title.png
dashboard:
blocks:
- { type: sonata.admin.block.admin_list, position: left }
templates:
dashboard: "@SonataAdmin/Core/dashboard.html.twig"
sonata_block:
default_contexts: [sonata_page_bundle]
blocks:
sonata.admin.block.admin_list: ~
sonata_user:
security_acl: true
manager_type: orm
我的fos_user.yaml:
fos_user:
db_driver: orm
firewall_name: main
user_class: App\Entity\User
group:
group_class: App\Entity\Group #Sonata\user-bundle\Entity\BaseGroup
group_manager: sonata.user.orm.group_manager
service:
user_manager: sonata.user.orm.user_manager
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
实体:
<?php
namespace App\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
}
}
<?php
namespace App\Entity;
use FOS\UserBundle\Model\Group as BaseGroup;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class Group extends BaseGroup
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
}
}
当我尝试访问管理面板时,我没有任何问题。当我尝试列出或创建值(“组”或“用户”)时出现错误。
答案 0 :(得分:0)
我添加了这些行:
sonata_user:
security_acl: true
manager_type: orm
class:
user: App\Entity\User
group: App\Entity\Group
但是出现另一个错误:
(1/1) InvalidArgumentException
Model class "App\Entity\User" does not correspond to manager type "orm".