magento _redirect with parameters that have + or /

和自甴很熟 提交于 2019-12-18 07:01:12

问题


seems like a call to

$this->_redirect('*/*/myaction',$myargs);

does not properly escape the arguments so if

$myargs=array(p1=>'string that has + or / within it')

the created URL will be something like:

 ..../myaction/?p1/string%20that%20has%20+%20or%20/%20within%20it

causing the getParams collection on the action to have p1 with value 'string that has or ' <- plus sign missing and value broken and ' within it' with no value or something similar.

is there any standard way I should handle the arguments before passing them to _redirect ?

Eyal


回答1:


Yes, there are two standard ways.

  1. Pass all your params as route params, but encode them with php urlencode() func:

    foreach ($myargs as $key => $val) {
        $myargs[$key] = urlencode($val);
    }
    $this->_redirect('*/*/myaction', $myargs);
    

  2. Pass your params as query params

    $this->_redirect('*/*/myaction', array('_query', $myargs));
    

You'd better take second approach, because your params logically are not route but query parameters. Magento is made with a lot of architecture thinking, so it usually points better ways to do stuff - that's why in your case it's easier to send params using second way.

Notice: _redirect() internally uses Mage_Core_Model_Url, so everything said in this answer is true for all other url-forming routines and all usages of Url model.




回答2:


refer to http://www.blooberry.com/indexdot/html/topics/urlencoding.htm#whatwhy and read the section "Reserved characters"



来源:https://stackoverflow.com/questions/4538422/magento-redirect-with-parameters-that-have-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!