Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2 DoctrineMongoDBBundle:创建存储库类后获得空结果_Php_Mongodb_Symfony - Fatal编程技术网

Php Symfony2 DoctrineMongoDBBundle:创建存储库类后获得空结果

Php Symfony2 DoctrineMongoDBBundle:创建存储库类后获得空结果,php,mongodb,symfony,Php,Mongodb,Symfony,很抱歉提出这么长的问题,但我认为对于经验丰富的symfony和mongodb开发人员来说,这很简单。 Q:如果我生成repository类,那么所有repositoryfindAll()、findBy()、findOneBy()、findBy*()都会失败。为什么失败? 低于我的作曲状态 "require": { "php": ">=5.3.9", "symfony/symfony": "2.8.*", "doctrine/orm": "^

很抱歉提出这么长的问题,但我认为对于经验丰富的symfony和mongodb开发人员来说,这很简单。 Q:如果我生成repository类,那么所有repository
findAll()、findBy()、findOneBy()、findBy*()
都会失败。为什么失败? 低于我的作曲状态

"require":
 {
        "php": ">=5.3.9",
        "symfony/symfony": "2.8.*",
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.11.3",
        "sensio/distribution-bundle": "~5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",
        "doctrine/mongodb-odm": "^1.1",
        "doctrine/mongodb-odm-bundle": "^3.2"
    }
控制器方法如下所示

     /**
     * @Route("survey/{token}", name="survey_index")
     */
    public function indexAction($token){
        // if i remove repository, below query gives perfect result.
        $survey = $this->get('doctrine_mongodb')
        ->getRepository('CoreBundle:Survey')->findAll();

        return $this->render('CoreBundle:Survey:index.html.twig',array('survey'=>$survey));
    }
文档类如下所示

namespace CoreBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
 * @ODM\Document(collection="survey_master")
 * @ODM\Document(repositoryClass="CoreBundle\Repository\SurveyRepository")
 */
class Survey {

    /**
     * @ODM\Id
     */
    protected $id;

    /**
     * @ODM\Field(type="string")
     */
    protected $name;

// setters and getters below
}
如果我删除

*@ODM\Document(repositoryClass=“CoreBundle\Repository\SurveyRepository”)

并执行缓存清除,一切正常。

调查报告类

namespace CoreBundle\Repository;

use Doctrine\ODM\MongoDB\DocumentRepository;

/**
 * SurveyRepository
 *
 * This class was generated by the Doctrine ODM. Add your own custom
 * repository methods below.
 */
class SurveyRepository extends DocumentRepository
{


}

Survey有两个带有
@ODM\Document
的注释,它们会覆盖自身


将两个参数放在一个注释中。

所有方法如何失败?@martin它为
findAll()
返回空数组
[]
。如果我删除存储库,它会给出完美的结果。
Survey
有两个注释,带有
@ODM\Document
,我认为它们会覆盖它们自己。你能试着把这两个参数放在一个注释中吗?@martin Ok。我试了一下,然后告诉你。像这样
*@ODM\Document(collection=“survey\u master”,repositoryClass=“CoreBundle\Repository\SurveyRepository”)
,对吗?