【问题标题】:FOSUserBundle managing In EasyAdminBundle(( The "User" entity must define its associated Doctrine entity class using the "class" option))SymfonyFOSUserBundle 在 EasyAdminBundle 中管理((“用户”实体必须使用“类”选项定义其关联的 Doctrine 实体类))Symfony
【发布时间】:2018-08-09 05:27:39
【问题描述】:

我正在使用带有 FOSUserBundle~2.0 和 EasyAdminBundle^1.17 的 Symfony 3.4。一切正常。我可以登录到系统并创建用户((当然带有推荐行))我使用这个toutaril 但是当我想在 EasyAdminBundle 中管理时,我遇到了这个错误

The "User" entity must define its associated Doctrine entity class using the "class" option.

这是我的 config.yml

..
.
.
entities:
            User:
            label: 'user'
            list:
                 actions:
                        - {name: 'delete', label: 'del' }
                        - {name: 'edit' , lable: 'edite'}
                 title: 'user'
                 fields:
                        - username
                        - email
                        - enabled
                        - lastLogin
            class: AppBundle\Entity\User
            form:
                fields:
                    - username
                    - email
                    - enabled
                    - lastLogin
                    # if administrators are allowed to edit users' passwords and roles, add this:
                    - { property: 'plainPassword', type: 'text', type_options: { required: false } }
                    - { property: 'roles', type: 'choice', type_options: { multiple: true, choices: { 'ROLE_USER': 'ROLE_USER', 'ROLE_ADMIN': 'ROLE_ADMIN' } } }

.
.
.

这是用户实体

<?php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
 /**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

【问题讨论】:

  • 应该是你的YAML文件的代码缩进问题。

标签: php symfony fosuserbundle symfony-3.4 easyadmin


【解决方案1】:

用户实体的所有选项都应该嵌套在用户下

    entities:
            User:
                label: 'user'
                list:
                     actions:
                        - {name: 'delete', label: 'del' }
                        - {name: 'edit' , lable: 'edite'}
                     title: 'user'
                     fields:
                        - username
                        - email
                        - enabled
                        - lastLogin
                class: AppBundle\Entity\User
                form:
                    fields:
                      - username
                      - email
                      - enabled
                      - lastLogin
                      # if administrators are allowed to edit users' passwords and roles, add this:
                      - { property: 'plainPassword', type: 'text', type_options: { required: false } }
                      - { property: 'roles', type: 'choice', type_options: { multiple: true, choices: { 'ROLE_USER': 'ROLE_USER', 'ROLE_ADMIN': 'ROLE_ADMIN' } } }

【讨论】:

    猜你喜欢
    • 2018-08-04
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 2021-08-14
    • 2014-09-30
    • 2018-06-03
    • 1970-01-01
    相关资源
    最近更新 更多