Laravel& Couchdb-ODM-注释"@Doctrine \ ODM \ CouchDB \ Mapping \ Annotations \ Document"不存在,或无法自动加载 [英] Laravel & Couchdb-ODM - The annotation "@Doctrine\ODM\CouchDB\Mapping\Annotations\Document" does not exist, or could not be auto-loaded

查看:97
本文介绍了Laravel& Couchdb-ODM-注释"@Doctrine \ ODM \ CouchDB \ Mapping \ Annotations \ Document"不存在,或无法自动加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Laravel 4.2中使用couchdb-odm,但是我一直在出错.最后一个是:

I want to use couchdb-odm in Laravel 4.2 but I keep on getting errors. The last one is:

[语义错误] IO \ Documents \ Article类中的注释"@Doctrine \ ODM \ CouchDB \ Mapping \ Annotations \ Document"不存在,或者无法自动加载.

[Semantical Error] The annotation "@Doctrine\ODM\CouchDB\Mapping\Annotations\Document" in class IO\Documents\Article does not exist, or could not be auto-loaded.

我主要复制了sandbox/bootstrap.php,并尝试了从以前的答案中解决同一问题的一些建议.这是我目前拥有的:

I copied mostly the sandbox/bootstrap.php and tried a couple of recommendations from previous answers in the same problem. Here is currently what I have:

我的composer.json具有:

My composer.json has:

"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"
},

我也试图将学说/共同点放在自动加载部分,但这实际上并没有做任何事情.

I also attempted to put the doctrine/common in the autoload section but that did not really do anything.

文章类别:

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的初学者,因此加深了困惑.

I am still a beginner of couchdb so that adds up in the confusion.

推荐答案

composer dump-autoload达到了目的.

此外,这是我的控制器的更新:

Also, here is an update to my controller:

    $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 ()

这篇关于Laravel&amp; Couchdb-ODM-注释"@Doctrine \ ODM \ CouchDB \ Mapping \ Annotations \ Document"不存在,或无法自动加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆