[英]Symfony2 Route get parameter only if integer
我在routing.yml文件中定义了路由
一条路线是:
Profile_user_profile:
path: /profile/{id}
defaults: { _controller: ProfileBundle:Users:profile }
methods: [get]
第二是:
Profile_accept_connection_proposal:
path: /profile/acceptProposal
defaults: { _controller:ProfileBundle:Users:acceptConnectionProposal }
methods: [put]
没有方法的第一条路线:[get]听取并[put]请求并在它到达路由定义之前捕获第二个url。 如果url是数字,是否有定义检查参数的方法。
您现在可以在控制器中使用Annotations执行此操作,如下所示:
class UserController extends AbstractController
{
/**
* @Route("/profile/{id}", name="user_profile", requirements={"id"="\d+"})
*/
public function profile($id)
{
// ...
}
}
有关Symfony文档的更多信息专门定义路由要求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.