3

似乎是在呼吁

$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 具有值 'string that has or ' <- plus sign missing and value broken and ' inside' 没有值或类似的东西。

在将参数传递给 _redirect 之前,我应该有什么标准方法来处理它们?

埃亚尔

4

2 回答 2

9

是的,有两种标准方式。

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

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

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

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

您最好采用第二种方法,因为您的参数在逻辑上不是路由而是查询参数。Magento 是用很多架构思想制作的,所以它通常会指出更好的方法来做事——这就是为什么在你的情况下使用第二种方式发送参数更容易。

注意:_redirect() 在内部使用 Mage_Core_Model_Url,所以这个答案中所说的一切对于所有其他 url 形成例程和 Url 模型的所有用法都是正确的。

于 2010-12-27T16:54:31.887 回答
1

请参阅http://www.blooberry.com/indexdot/html/topics/urlencoding.htm#whatwhy并阅读“保留字符”部分

于 2010-12-27T11:51:47.010 回答