使用Symfony2和FOSRestBundle我试图实现API方法,这些API方法在路由中定义了一些固定参数以及查询字符串中可能存在的一些可选参数。使用Symfony中的FOSRestBundle混合路由和查询参数
例如:
http://somesite.com/api/method/a/b
http://somesite.com/api/method/c/d?x=1&y=2
据the documentation for FOSRestBundle,ParamFetcher是要做到这一点,利用@QueryParam标注的正确方法。不过,我已经有一个控制器,定义如下:
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\View;
class MyController extends Controller
{
/**
* @Get("/method/{a}/{b}")
* @View()
*/
public function getMethodAction($a, $b)
{
// do stuff
return array('foo' => 'bar');
}
}
现在看来,我需要能够获得访问ParamFetcher的实例,但我不知道如何(以及谷歌搜索并没有帮助太多) 。我从文档中知道,我可以简单地改变方法签名来并入ParamFetcher,但是,当我这样做时,它将参数移动到查询字符串中,这是我不能拥有的。
是否有混合两者的方法,还是应该放弃ParamFetcher并直接使用Symfomy的内置Request对象直接检查请求?
感谢您的跟进 - 我终于弄清楚了这一点,并忽略了回来。 – futureal