我在symfony 2.7.2中使用couchDb。
我有几个疑问。现在我安装了这个Bundle
我创建了一个实体来测试<?php
namespace foo'GarageBundle'Document;
use Doctrine'ODM'CouchDB'Mapping'Annotations as CouchDB;
/**
* @CouchDB'Document
*/
class Utente
{
/** @CouchDB'Id */
private $id;
/** @CouchDB'Field(type="string") */
private $nome;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nome
*
* @param string $nome
* @return Utente
*/
public function setNome($nome)
{
$this->nome = $nome;
return $this;
}
/**
* Get nome
*
* @return string
*/
public function getNome()
{
return $this->nome;
}
}
在我的控制器中我添加了这个代码
$dm = $this->container->get('doctrine_couchdb.client.default_connection');
$doc = $this->container->get('doctrine_couchdb.odm.default_document_manager');
try{
$dm->createDatabase($dm->getDatabase());
}catch('Exception $e){
$msg = $e->getMessage();
}
$user = new Utente();
$user->setNome('foo');
$doc->persist($user);
$doc->flush();
我的配置。yml是
doctrine_couch_db:
client:
default_connection: default
connections:
default:
dbname: symfony2
odm:
default_document_manager: default
document_managers:
default:
auto_mapping: true
我创建了数据库,但是我不能插入新的文档,我得到了这个错误
The class 'foo'GarageBundle'Document'Utente' was not found in the chain configured namespaces
和我不明白为什么它是有用的使用一个bundle作为我正在使用(我知道这可能是一个愚蠢的问题),为什么我要使用* @CouchDB'Document
而不是@Document
在我的实体内?
似乎是与实体类的名称空间有关的问题。
的CouchDocument子命名空间你的bundle,而不是Document(它是由DoctrineMongoDBBundle)
因此,为User
类和您使用的其他coach使用不同的名称空间,如下所示:
namespace foo'GarageBundle'CouchDocument;
特别是:
<?php
namespace foo'GarageBundle'CouchDocument;
use Doctrine'ODM'CouchDB'Mapping'Annotations as CouchDB;
/**
* @CouchDB'Document
*/
class Utente
{
希望对您有所帮助
/**
* @CouchDB'Document
* @CouchDB'Index
*/
class Utente
{