【问题标题】:Symfony + Doctrine ODM "The class was not found in the chain configured namespaces CoreBundle/Document"Symfony + Doctrine ODM“在链配置的命名空间CoreBundle / Document中找不到该类”
【发布时间】:2015-11-27 11:13:39
【问题描述】:

我找不到导致此问题的原因。我有一个名为 CoreBundle (src/CoreBundle) 的包,其中有一个实体目录 (src/CoreBundle/Entity)。该目录存储所有实体。目前只有用户实体(src/CoreBundle/Entity/User.php)。以下是内容:

namespace Mokapot\CoreBundle\Entity;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @MongoDB\Document(collection="users")
 */
class User implements UserInterface {

    /**
     * @MongoDB\Id
     */
    protected $id;

    /**
     * @MongoDB\String
     */
    protected $username;

    /**
     * @MongoDB\String
     */
    protected $password;

    /**
     * @MondoDB\Collection
     */
    private $roles;

    public function getRoles() {
        $roles = $this->roles;
        if(empty($roles)) {
            $roles = ['ROLE_USER'];
        }
        return array_unique($roles);
    }

    public function setRoles(array $roles) {
        $this->roles = $roles;
    }

    public function getSalt() {
        return;
    }

    public function eraseCredentials() {

    }

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getUsername() {
        return $this->username;
    }

    public function setUsername($username) {
        $this->username = $username;
    }

    public function getPassword() {
        return $this->password;
    }

    public function setPassword($password) {
        $this->password = $password;
    }

}

这是我的 config.yml 教义:

doctrine_mongodb:
    connections:
        default:
            server: "%dbhost%"
            options: {}
    document_managers:
        default:
            database: "%dbname%"
            auto_mapping: false
            mappings:
                CoreBundle:
                    mapping: true
                    type: annotation
                    dir: Entity
                    prefix:               ~
                    alias:                ~
                    is_bundle: true

编辑:更改了标题。

【问题讨论】:

    标签: php symfony doctrine doctrine-odm


    【解决方案1】:

    尝试像这样更改您的命名空间:

    namespace Mokapot\CoreBundle\Document;
    

    还有目录:

    src/CoreBundle/Document
    

    官方文档:

    假设您正在构建一个需要显示产品的应用程序。甚至不用考虑 Doctrine 或 MongoDB,您就已经知道需要一个 Product 对象来表示这些产品。在 AcmeStoreBundle 的 Document 目录中创建此类:

    【讨论】:

    • 我希望我的命名空间像实体一样。
    【解决方案2】:

    我找到了解决方案。我将 prefix 变量更改为

    prefix: CoreBundle\Entity
    

    【讨论】:

      猜你喜欢
      • 2016-10-31
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      相关资源
      最近更新 更多