현재 FOSRestBundle과 함께 Symfony2를 사용하여 RESTful API를 개발 중입니다.FOSRestBundle 및 Mongodb 커서 객체를 json으로
나는 Mongodb를 좋아한다. 그래서 나는 그것을 구현했다. 여기에 내 usercontroller의 발췌 문장이있다.
/**
* @return View view instance
* @View()
*/
public function allAction() {
$users = $this->get('doctrine_mongodb')
->getRepository('FantasytdUserBundle:User')
->findByUsername('Elvar');
return $users;
}
그래서 나는 데이터베이스에서 결과를 산출하는 사용자를 찾고 있습니다. mysql 데이터베이스에서이 작업을 수행했다. 그러나 mongodb의 경우, get 메소드는 Cursor 객체를 반환하고, 반환 될 때 이와 같은 것을 얻습니다.
[{"message":"[Semantical Error] Annotation @Secure is not allowed to be declared on class JMS\\SecurityExtraBundle\\Annotation\\Secure. You may only use this annotation on these code elements: METHOD.","class":"Doctrine\\Common\\Annotations\\AnnotationException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"\/Users\/Elvar\/Projects\/fantasytd\/backend\/vendor\/doctrine\/common\/lib\/Doctrine\/Common\/Annotations\/AnnotationException.php","line":52,"args":[]},
그리고 계속됩니다.
어떻게 이러한 커서 개체에 접근해야합니까?
'Secure (roles = "ROLE_ADMIN")'주석을 사용하여 전체 컨트롤러를 보안하려고하면, 얻은 에러는 Symfony 2.1에서 발생합니다. 대신 @PreAuthorize ("hasRole ('ROLE_ADMIN')")'을 사용하십시오 (http://stackoverflow.com/a/12001097/601386 참조). – flu
@PreAuthorize를 사용한다면'jms_security_extra :'에서 설정에'expressions : true'을 추가하는 것을 잊지 마십시오. 디폴트는'false'입니다. – flu