【问题标题】:FOSUserBundle Symfony2 Doctrine Mapping exception: class doesn't exist (works on Windows 8.1 but not on Ubuntu 14.04)FOSUserBundle Symfony2 Doctrine Mapping 异常:类不存在(适用于 Windows 8.1,但不适用于 Ubuntu 14.04)
【发布时间】:2014-12-14 01:24:10
【问题描述】:

我正在尝试使用 FOSUserBundle 实现注册。我按照https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md 的教程进行操作

我使用php app/console doctrine:schema:update --force 命令更新了我的数据库,并且所有条目都已更新。但是当我尝试在浏览器中加载我的项目时,我得到:

MappingException: Class 'Demo\BusinessBundle\Entity\BusinessUser' does not exist

我的业务用户实体:

<?php
namespace Demo\BusinessBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;

/**
* @ORM\Entity
* @ORM\Table(name="business_users")
*/
class BusinessUser extends BaseUser
{
  /**
    * @ORM\Column(type="integer")
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    protected $id;
    /**
    * @ORM\Column(type="string", length=255)
    */
    protected $surname;

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set surname
     *
     * @param string $surname
     * @return BusinessUser
     */
    public function setSurname($surname)
    {
        $this->surname = $surname;

        return $this;
    }

    /**
     * Get surname
     *
     * @return string 
     */
    public function getSurname()
    {
        return $this->surname;
    }
}

我认为这与app/config.yml 文件有关。因为当我更改user_class: 中提供的实体名称时,我将其更改为的类名出现相同的错误。

来自config.yml的那部分:

# FOSUserBundle configuration
fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: Demo\BusinessBundle\Entity\BusinessUser

config.yml中的教义块:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

运行php app/console doctrine:mapping:info的结果:

Found 3 mapped entities:
[OK]   Demo\BusinessBundle\Entity\BusinessUser
[OK]   FOS\UserBundle\Model\User
[OK]   FOS\UserBundle\Model\Group

编辑 1: 我复制了同一个项目并在 Windows 8.1 上尝试了它,它工作得很好。但在 Ubuntu 14.04 LTS 上却没有。

【问题讨论】:

  • 您能提供来自config.ymldoctrine 块吗?
  • 可以肯定的是,当前安装过程中存在一个错误,当您直接在控制台中运行它并安装旧版本时,composer 无法正确检测到版本标签'~2.0@dev'。你能检查一下你的版本吗?
  • 好的,我已经添加了学说块。
  • 不确定在哪里检查,但Changelog.md 中的两个最新条目是:### 2.0.0-alpha1 (2014-09-26) 和 ### 2.0.0 (2014-XX -XX)。所以我相信它是 2.0。
  • hm.. 没有好主意 :( 也许清除缓存?

标签: symfony doctrine-orm yaml fosuserbundle ubuntu-14.04


【解决方案1】:

尝试设置auto_mapping: false

# app/config/config_dev.php
doctrine:
    orm:
        auto_mapping: false
        mapping:
            BusinessBundle: ~

AppBundle 而不是BusinessBundle

【讨论】:

    【解决方案2】:

    我刚刚浪费了 3 个小时来调试这个问题。我希望我能节省一些人的时间。在极少数情况下,您的作曲家自动加载可能会和您一起玩游戏。尝试执行composer dumpautoload,清除缓存/var/cache/*/,然后重试。我遇到了完全相同的问题——实体具有正确的命名空间,它正在被映射,但 symfony 无法找到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      相关资源
      最近更新 更多