drymoeuka282427675
2017-10-30 12:43
浏览 34
已采纳

在Symfony的url中设置不需要的参数

How to set one action to multiply URLs in Symfony2.8 (annotation type)? I need something like this: /credit/{credit-type} where "credit-type" parameter may be empty: /credit/ I used this:

/**
     * @Route("/{credit}/{credit-type}/", name="credit_page_single", defaults={"credit-type" = "null"})
     * @Method("GET")
     *
     * @param $credit
     * @param $credit-type
     * @param Request $request
     *
     * @return Response
     */

Same thing in Laravel you can get when put the '?' symbol after the parameter that could be empty: /credit/{credit-type?}/

图片转代码服务由CSDN问答提供 功能建议

如何在Symfony2.8(注释类型)中设置一个多重URL的操作? 我需要这样的东西: / credit / {credit-type} 其中“credit-type”参数可能为空: / credit / 我用过这个:

  / ** \  n * @Route(“/ {credit} / {credit-type} /”,name =“credit_page_single”,defaults = {“credit-type”=“null”})
 * @Method(“GET”)\  n * 
 * @param $ credit 
 * @param $ credit-type 
 * @param请求$ request 
 * 
 * @return Response 
 * / 
   \  n 
 

在Laravel中你可以得到同样的东西'?' 参数后面的符号可能为空: / credit / {credit-type?} /

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyan4243 2017-10-30 12:46
    已采纳

    You can set multiple routes to you action, like this :

    /**
     * @Route("/{credit}/{credit-type}/", name="credit_page_single", defaults={"credit-type" = "null"})
     * @Route("/{credit}/", name="credit_page_single_without_parameter")
     * @Method("GET")
     *
     * @param $credit
     * @param $credit-type
     * @param Request $request
     *
     * @return Response
     */
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题