我想在Laravel 4.2中使用couchdb-odm,但我一直在收到错误。最后一个是:
[语义错误]注释" @Doctrine \ ODM \ CouchDB \ Mapping \ Annotations \ Document"在类IO \ Documents \ Article中不存在,或者无法自动加载。
我主要复制了sandbox / bootstrap.php,并在同一问题中尝试了以前答案中的一些建议。这是我目前所拥有的:
我的composer.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"
},
我还尝试将doctrine / common放在autoload部分,但实际上并没有做任何事情。
文章类:
namespace IO\Documents;
use Doctrine\ODM\CouchDB\Mapping\Annotations\Document;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Document(indexed=true)
*/
class Article {}
我的控制器:
$database = "test";
$httpClient = new \Doctrine\CouchDB\HTTP\SocketClient();
$resp = $httpClient->request('PUT', '/' . $database);
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
// doesn't exist so I comment out
// $reader->registerAnnotationClasses('Doctrine\ODM\CouchDB\Mapping\\');
$paths = __DIR__ . "/Documents";
$metaDriver = new \Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver($reader, $paths);
$config = new \Doctrine\ODM\CouchDB\Configuration();
$config->setProxyDir(\sys_get_temp_dir());
$config->setMetadataDriverImpl($metaDriver);
$config->setLuceneHandlerName('_fti');
$couchClient = new \Doctrine\CouchDB\CouchDBClient($httpClient, $database);
$dm = \Doctrine\ODM\CouchDB\DocumentManager::create($couchClient, $config);
$article1 = new Article();
$article1->setTitle("Who is John Galt?");
$article1->setBody("Find out!");
$dm->persist($article1);
$dm->flush();
$dm->clear();
我仍然是couchdb的初学者,因此混淆了。
答案 0 :(得分:1)
composer dump-autoload
完成了这个伎俩。
此外,这是对我的控制器的更新:
$annotationNs = 'Doctrine\\ODM\\CouchDB\\Mapping\\Annotations';
$couchPath = '/path/to/vendor/doctrine/couchdb-odm/lib';
\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace($annotationNs, $couchPath);
$databaseName = "test";
$documentPaths = array("IO\Documents");
$httpClient = new \Doctrine\CouchDB\HTTP\SocketClient();
$dbClient = new \Doctrine\CouchDB\CouchDBClient($httpClient, $databaseName);
$config = new \Doctrine\ODM\CouchDB\Configuration();
$metadataDriver = $config->newDefaultAnnotationDriver($documentPaths);
$config->setProxyDir(__DIR__ . "/proxies");
$config->setMetadataDriverImpl($metadataDriver);
$dm = new \Doctrine\ODM\CouchDB\DocumentManager($dbClient, $config);
$article1 = new Article();
$article1->setTitle("Who is John Galt?");
$article1->setBody("Find out!");
$dm->persist($article1);
$dm->flush($article1);
我的文章课程:
<?php
namespace IO\Documents;
use Doctrine\ODM\CouchDB\Mapping\Annotations as CouchDB;
/**
* @Document
*/
class Article ()