Класс 'App \ Document \ User' не найден в настроенных пространствах имен цепочки - PullRequest
0 голосов
/ 24 ноября 2018

Я только что установил mongodb с symfony4.1.

Когда я хочу сохранить простого пользователя в базе данных, я получаю эту ошибку (заголовок):

Uncaught PHP Exception Doctrine \ Common \ Persistence \ Mapping \ MappingException: "Класс 'App \ Document \ User' не найден в настроенных пространствах имен цепочек

enter image description here

Вот мой контроллер:

/**
 * @Route("/mongoTest")
 * @Method("GET")
 * @param DocumentManager $dm
 * @return JsonResponse
 */
public function mongoTest(DocumentManager $dm)
{
    $user = new User();
    $user->setEmail("hello@medium.com");
    $user->setFirstname("Matt");
    $user->setLastname("Matt");
    $user->setPassword(md5("123456"));
    $dm->persist($user);
    $dm->flush();
    return new JsonResponse(array('Status' => 'OK'));
}

Конфиг:

doctrine_mongodb:
  connections:
    default:
      server: "%mongodb_server%"
      options: {}
  default_database: "%mongodb_database_name%"
  document_managers:
    default:
      auto_mapping: true
  default_commit_options: ~

Вот мой документ:

<?php

namespace App\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
 * @MongoDB\Document
 */
class User
{
    /**
     * @MongoDB\Id
     */
    protected $id;

    /**
     * @MongoDB\Field(type="string")
     */
    protected $firstname;

    /**
     * @MongoDB\Field(type="string")
     */
    protected $lastname;

    /**
     * @MongoDB\Field(type="string")
     */
    protected $email;

    /**
     * @MongoDB\Field(type="string")
     */
    protected $password;

    /**
     * @MongoDB\Field(type="date")
     */
    protected $create_date;

    // ...
}

У кого-нибудь есть идеи?

Спасибо большое !!

1 Ответ

0 голосов
/ 25 ноября 2018

Я нашел ответ:

Я не использую связки.

doctrine_mongodb:
  connections:
    default:
      server: "%mongodb_server%"
      options: {}
  default_database: "%mongodb_database_name%"
  document_managers:
    default:
      mappings:
        # ...
        App:
          type: annotation
          dir: "%kernel.root_dir%/../src/Document"
          is_bundle: false
          prefix: App\Document
          alias: App
  default_commit_options: ~
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...