很抱歉这个问题很长,但我认为对于经验丰富的symfony和mongodb开发者来说很简单。
问:如果我生成存储库类,则所有存储库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")
并执行缓存清除,一切正常。
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
{
}
答案 0 :(得分:2)
调查有两个注释@ODM\Document
覆盖自己。
将两个参数都放在一个注释中。