magento _redirect带有+或/的参数 [英] magento _redirect with parameters that have + or /

查看:59
本文介绍了magento _redirect带有+或/的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像是对

的调用

$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

解决方案

是的,有两种标准方法.

  1. 将所有参数传递为路由参数,但使用php urlencode()func对其进行编码:

  2. 将您的参数传递为查询参数

您最好采用第二种方法,因为从逻辑上讲,您的参数不是路由而是查询参数. 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.

  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.

这篇关于magento _redirect带有+或/的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆