Symfony2 FOS 用户不是有效实体

发布于 2024-12-23 15:57:48 字数 2353 浏览 0 评论 0原文

我不确定我在这里做错了什么。

我按照有关如何安装 fos 捆绑包的说明进行操作,但遇到了问题。

我收到以下错误:

PHP 致命错误:未捕获的异常 'Doctrine\ORM\Mapping\MappingException' 带有消息 'Class RS\Entity\User 不是有效的实体或映射的超类。在 路径\vendor\doctrine\lib\Doctrine\ORM\Mapping\MappingException.php:142

我的用户类位于 /src/RS/Entity/User.php

并且我有'RS' => __DIR__.'/../vendor/reportsuite/src'in app/autoload.php

该类是

<?php
// /src/RS/Entity/User.php

namespace RS\Entity;

use FOS\UserBundle\Entity\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
    }
}

据我所知这是一个映射实体,除非我错过了一些东西?

我还尝试过通过捆绑包和另一个捆绑包(如 Acme/UserBundle/Entity/User.php )创建实体,

# Doctrine Configuration
doctrine:
    dbal:
        default_connection:       default
        connections:
            default:
                dbname:           axpdb
                user:             %database_user%
                password:         %database_password%
                host:             %database_host%
                port:             %database_port%
                charset:          UTF8
            reportsuite:
                dbname:           reportsuite
                user:             %database_user%
                password:         %database_password%
                host:             %database_host%
                port:             %database_port%
                charset:          UTF8
    orm:
        entity_managers:
            default:
                connection:       default
                mappings:
                    ReportSuiteMainMenuBundle: ~
            reportsuite:
                connection:       reportsuite
                mappings:


# Security
jms_security_extra:
    secure_controllers:  true
    secure_all_services: false

# FOS User Config
#fos_user:
#    db_driver: orm
#    firewall_name: main
#    user_class: RS\Entity\User
#    model_manager_name: reportsuite

我有 2 个需要访问的数据库,并且我已经注释掉了 fos 内容,以便我可以继续在职的。

im not sure what ive done wrong here.

I am following the instruction on how to install the fos bundle and have come across a problem.

I am getting the following error:

PHP Fatal error: Uncaught exception
'Doctrine\ORM\Mapping\MappingException' with message 'Class
RS\Entity\User is not a valid entity or mapped super class.' in
PATH\vendor\doctrine\lib\Doctrine\ORM\Mapping\MappingException.php:142

My user class is in /src/RS/Entity/User.php

And i have'RS' => __DIR__.'/../vendor/reportsuite/src'in app/autoload.php

The class is

<?php
// /src/RS/Entity/User.php

namespace RS\Entity;

use FOS\UserBundle\Entity\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
    }
}

As far as i can tell this is a mapped entity, unless im missing something?

Ive also tried creating the entity in by bundle and another bundle like Acme/UserBundle/Entity/User.php

# Doctrine Configuration
doctrine:
    dbal:
        default_connection:       default
        connections:
            default:
                dbname:           axpdb
                user:             %database_user%
                password:         %database_password%
                host:             %database_host%
                port:             %database_port%
                charset:          UTF8
            reportsuite:
                dbname:           reportsuite
                user:             %database_user%
                password:         %database_password%
                host:             %database_host%
                port:             %database_port%
                charset:          UTF8
    orm:
        entity_managers:
            default:
                connection:       default
                mappings:
                    ReportSuiteMainMenuBundle: ~
            reportsuite:
                connection:       reportsuite
                mappings:


# Security
jms_security_extra:
    secure_controllers:  true
    secure_all_services: false

# FOS User Config
#fos_user:
#    db_driver: orm
#    firewall_name: main
#    user_class: RS\Entity\User
#    model_manager_name: reportsuite

I have 2 databases that I need to access and I have commented out the fos stuff so i can continue working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

原谅过去的我 2024-12-30 15:57:49

您检查了命名空间吗?

我认为应该是:

namespace Namespace\YourBundle\Entity

您可以使用所有捆绑包中的实体。

Did You checkd a namespace ?

I think it should be:

namespace Namespace\YourBundle\Entity

You can use entites from all of Your bundles.

腹黑女流氓 2024-12-30 15:57:49

运行

touch Entity/*

一下就OK了。

Run

touch Entity/*

and you are OK.

韬韬不绝 2024-12-30 15:57:49

遇到这个问题 - 不要忘记注释 * @ORM\Entity 如下所示:

/**
 * Powma\ServiceBundle\Entity\User
 *
 * @ORM\Entity
 * @ORM\Table(name="users")
 */

Had this problem - don't forget the annotation * @ORM\Entity like below:

/**
 * Powma\ServiceBundle\Entity\User
 *
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文