douqian1296
2013-11-25 21:48
浏览 49
已采纳

Symfony2路由中实现多个参数[关闭]

Here is normal GET request URL

http://localhost/person.php?name='Jack'&age=25&gender='male'

How to implement it to Symfony2 routing?


After test here is my solution:

acme_person_info:
    pattern:  /person/name/{name}/age/{age}/gender/{gender}
    defaults: { _controller: AcmeUserBundle:Person:info }

class PersonController extends Controller
{
    public function infoAction($name, $age, $gender) 
    {
             // do something here
    }

}

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

这是正常的 GET 请求网址

   http://localhost/person.php?name ='Jack'& age = 25& gender ='male'
   
 
 

如何实施 到Symfony2路由?


在这里测试之后是我的解决方案:

  acme_person_info:
 pattern:/  person / name / {name} / age / {age} / gender / {gender} 
 defaults:{_ control:AcmeUserBundle:Person:info} 
   
 
 
\ n
 类PersonController扩展Controller 
 {
公共函数infoAction($ name,$ age,$ gender)
 {
 //在此处执行操作
} 
 
} \  n   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douruanfan3030 2013-11-26 07:36
    已采纳

    You should read the symfony doc anyway. see http://symfony.com/doc/current/book/routing.html

    // app/config/routing.yml
    person:
        path:      /person/{name}-{age}-{gender}
        defaults:  { _controller: AcmeBlogBundle:Person:index }
    
    // src/Acme/BlogBundle/Controller/PersonController.php
    namespace Acme\BlogBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    
    class PersonController extends Controller
    {
        public function indexAction($name, $age, $gender)
        {
            // do something
        }
    }
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题