magento _redirect带有+或/的参数 [英] magento _redirect with parameters that have + or /
问题描述
好像是对
的调用$this->_redirect('*/*/myaction',$myargs);
不能正确地转义参数 因此,如果
$myargs=array(p1=>'string that has + or / within it')
创建的URL将类似于:
..../myaction/?p1/string%20that%20has%20+%20or%20/%20within%20it
导致操作上的getParams集合具有 p1的值是'具有'或'<-的加号,且缺少加号且值已损坏,并且 在其中"没有任何价值或类似内容.
在将参数传递给_redirect之前,有什么标准的方法可以处理?
Eyal
是的,有两种标准方法.
-
将所有参数传递为路由参数,但使用php urlencode()func对其进行编码:
-
将您的参数传递为查询参数
您最好采用第二种方法,因为从逻辑上讲,您的参数不是路由而是查询参数. Magento具有很多架构思想,因此通常会指出更好的做事方式-这就是为什么在您的情况下,使用第二种方式发送param更容易.
注意:_redirect()内部使用Mage_Core_Model_Url,因此此答案中的所有内容对于所有其他形成网址的例程和Url模型的所有用法都是正确的.
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
Yes, there are two standard ways.
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);
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.
这篇关于magento _redirect带有+或/的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!