在我的项目中,我有一个BaseController类,它实现了我的所有控制器使用的几种方法。Symfony2注释继承
现在我想为该基类添加@QueryParam。我的阶级是这样的:
class DoctrineRESTQueryController extends FOSRestController
{
/**
* @QueryParam(name="start",default=0)
* @QueryParam(name="limit",default=null)
*/
public function getQueryResponseAction (ParamFetcher $paramFetcher) {
}
}
现在我有我从我的基本控制器延长实际控制人:
class DefaultController extends DoctrineRESTQueryController {
/**
* Retrieves all SI Prefixes in the database
*
* @Routing\Route("/siprefix", defaults={"method" = "get","_format" = "json"})
* @Routing\Method({"GET"})
* @ApiDoc(output="array<PartKeepr\SiPrefixBundle\Entity\SiPrefix>")
*
* @View()
*
* {@inheritdoc}
*/
public function getQueryResponseAction(ParamFetcher $paramFetcher) {
$paramFetcher->get("start");
}
}
不幸的是,Symfony2中似乎并没有从超类继承@QueryParam注释,因为对$ paramFetcher-> get(“start”)的调用导致出现异常“No @ QueryParam/@ RequestParam configuration for parameter'start'”。
是否有任何方法使注解继承工作,或任何其他解决方案,所以我不必将@QueryParam添加到我的每个控制器?
你真了不起!一个小小的修正: 定制的读者应该检查是否父类的方法确实存在: 如果($父类&& $ parentClass-> hasMethod($方法 - > getShortName())){$ = parentMethod $ parentClass-> getMethod ($方法 - > getShortName()); $ parentParams = parent :: getParamsFromMethod($ parentMethod); } return array_merge($ params,$ parentParams); } – Felicitus
我更新了我的答案。 –