[英]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.