Gasim
Gasim

Reputation: 7961

Symfony + Doctrine ODM "The class was not found in the chain configured namespaces CoreBundle/Document"

I can't find what is causing this issue. I have a bundle called CoreBundle (src/CoreBundle) and there is an Entity directory in it (src/CoreBundle/Entity). The directory stores all the entities. For now there is only User Entity (src/CoreBundle/Entity/User.php). Here are the contents:

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;
    }

}

Here is my config.yml for doctrine:

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

EDIT: Changed the title.

Upvotes: 2

Views: 1275

Answers (2)

Gasim
Gasim

Reputation: 7961

I have found the solution. I changed prefix variable to

prefix: CoreBundle\Entity

Upvotes: 0

scoolnico
scoolnico

Reputation: 3135

Try to change your namespace like that:

namespace Mokapot\CoreBundle\Document;

And the directory:

src/CoreBundle/Document

Official Documentation:

Suppose you're building an application where products need to be displayed. Without even thinking about Doctrine or MongoDB, you already know that you need a Product object to represent those products. Create this class inside the Document directory of your AcmeStoreBundle:

Upvotes: 1

Related Questions