2

我正在尝试使用 Doctrine (symfony2.1) 将一些数据保存到 MongoDB。这是我的实体:

// src/Acme/ReportsBundle/Entity/ReportCore.php
namespace Acme\ReportsBundle\Entity;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Doctrine\Common\Collections\ArrayCollection;
/**
 * @MongoDB\Document(collection="registeredReports")
 */
class ReportCore {

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

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

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

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

/**
* @MongoDB\Date
*/
protected $created;

/**
* @MongoDB\Date
*/
protected $createdBy;

/**
* @MongoDB\EmbedMany(targetDocument="ReportFields")
*/
protected $fields = array();

public function __construct () {
    $this->fields = new ArrayCollection();
}
// Setters, getters
}

这是嵌入式文档:

// src/Acme/ReportsBundle/Entity/ReportFields.php
namespace Acme\ReportsBundle\Entity;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
 *  @MongoDB\EmbeddedDocument
 */
class ReportFields {
/**
 * @MongoDB\Id
 */
protected $id;

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

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

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

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

    //Setters-getters...
}

这是控制器:

// src/Acme/ReportsBundle/Controller/ReportsController.php
namespace Acme\ReportsBundle\Controller;
use Acme\ReportsBundle\Entity\ReportCore;
use Acme\ReportsBundle\Entity\ReportFields;
use Acme\ReportsBundle\Form\Type\ReportCoreType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class ReportsController extends Controller {
    public function newAction (Request $request) {
$report = new ReportCore();
$fields1 = new ReportFields();
$report->getFields()->add($fields1);
$form = $this->createForm(new ReportCoreType(), $report);
    if ( $request->isMethod('POST') ) {
    $form->bind($request);
    if ( $form->isValid() ) {
        $dm = $this->get('doctrine_mongodb')->getManager();
    $dm->persist($report);
    $dm->flush();
    }
}
return $this->render('AcmeReportsBundle:Report:new.html.twig', array(
            'form' => $form->createView()
        ));
}

我的问题是 - 当我尝试将数据持久保存到数据库时,我得到

The class 'Acme\ReportsBundle\Entity\ReportCore' was not found in the chain configured namespaces FOS\UserBundle\Document

由于我对 Symfony 和 Doctrine 还很陌生 - 我无法弄清楚它与 FOSUserBundle 有什么关系,以及我做错了什么。

4

1 回答 1

2

您的 MongoDb-Schemas 应该在 Document 命名空间内

namespace Acme\ReportsBundle\Document;

于 2013-01-29T09:46:08.840 回答