How to get a url parameter in Magento controller?

后端 未结 3 1631
不思量自难忘°
不思量自难忘° 2020-12-25 14:13

Is there a Magento function to get the value of \"id\" from this url:

http://example.com/path/action/id/123

I know I can split the url on \"/\" to get the va

3条回答
  •  一整个雨季
    2020-12-25 14:36

    Magento's default routing algorithm uses three part URLs.

    http://example.com/front-name/controller-name/action-method
    

    So when you call

    http://example.com/path/action/id/123
    

    The word path is your front name, action is your controller name, and id is your action method. After these three methods, you can use getParam to grab a key/value pair

    http://example.com/path/action/id/foo/123
    
    //in a controller
    var_dump($this->getRequest()->getParam('foo'));
    

    You may also use the getParams method to grab an array of parameters

    $this->getRequest()->getParams()
    

提交回复
热议问题