我正在尝试使用Docrtrine(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有什么关系,以及我做错了什么。
答案 0 :(得分:2)
您的MongoDb-Schemas应位于Document名称空间
中 namespace Acme\ReportsBundle\Document;