我想在Laravel 4.2中使用couchdb-odm,但我一直得到错误。最后一个是:
[语义错误]类IODocumentsArticle中的注释"@DoctrineODMCouchDBMappingAnnotationsDocument"不存在,或者无法自动加载。
我复制了大部分的sandbox/bootstrap.php,并尝试了几个建议从以前的答案在同一问题。以下是我当前的内容:
我的作曲家。json:
"require": {
"laravel/framework": "4.2.*",
"symfony/console": ">=2.0",
"doctrine/dbal": "2.5.*@dev",
"doctrine/migrations": "1.0.*@dev",
"doctrine/common": "2.4.*",
"doctrine/couchdb": "@dev",
"doctrine/couchdb-odm": "dev-master"
},
我也试着在自动加载一节中加入原则/common,但那并没有真正起什么作用。
文章类:
namespace IODocuments;
use DoctrineODMCouchDBMappingAnnotationsDocument;
use DoctrineCommonCollectionsArrayCollection;
/**
* @Document(indexed=true)
*/
class Article {}
我的控制器:
$database = "test";
$httpClient = new DoctrineCouchDBHTTPSocketClient();
$resp = $httpClient->request('PUT', '/' . $database);
$reader = new DoctrineCommonAnnotationsAnnotationReader();
// doesn't exist so I comment out
// $reader->registerAnnotationClasses('DoctrineODMCouchDBMapping\');
$paths = __DIR__ . "/Documents";
$metaDriver = new DoctrineODMCouchDBMappingDriverAnnotationDriver($reader, $paths);
$config = new DoctrineODMCouchDBConfiguration();
$config->setProxyDir(sys_get_temp_dir());
$config->setMetadataDriverImpl($metaDriver);
$config->setLuceneHandlerName('_fti');
$couchClient = new DoctrineCouchDBCouchDBClient($httpClient, $database);
$dm = DoctrineODMCouchDBDocumentManager::create($couchClient, $config);
$article1 = new Article();
$article1->setTitle("Who is John Galt?");
$article1->setBody("Find out!");
$dm->persist($article1);
$dm->flush();
$dm->clear();
我仍然是couchdb的初学者,所以这增加了困惑。
composer dump-autoload
做到了。
另外,这里是一个更新到我的控制器:
$annotationNs = 'Doctrine\ODM\CouchDB\Mapping\Annotations';
$couchPath = '/path/to/vendor/doctrine/couchdb-odm/lib';
DoctrineCommonAnnotationsAnnotationRegistry::registerAutoloadNamespace($annotationNs, $couchPath);
$databaseName = "test";
$documentPaths = array("IODocuments");
$httpClient = new DoctrineCouchDBHTTPSocketClient();
$dbClient = new DoctrineCouchDBCouchDBClient($httpClient, $databaseName);
$config = new DoctrineODMCouchDBConfiguration();
$metadataDriver = $config->newDefaultAnnotationDriver($documentPaths);
$config->setProxyDir(__DIR__ . "/proxies");
$config->setMetadataDriverImpl($metadataDriver);
$dm = new DoctrineODMCouchDBDocumentManager($dbClient, $config);
$article1 = new Article();
$article1->setTitle("Who is John Galt?");
$article1->setBody("Find out!");
$dm->persist($article1);
$dm->flush($article1);
My Article类:
<?php
namespace IODocuments;
use DoctrineODMCouchDBMappingAnnotations as CouchDB;
/**
* @Document
*/
class Article ()