Magento _redirect with parameters that have + or /

looks like a challenge

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

does not properly execute arguments therefore if

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

the generated URL will look something like this:

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

as a result, the getParams collection in action will have p1 with the value ", which has either the '<- plus sign is absent and the value is broken and" inside it "without value or something like that.

Is there any standard way to handle arguments before passing them to _redirect?

Eyal

+3
source share
2 answers

Yes, there are two standard ways.

  • Pass all your parameters as route parameters, but encode them with php urlencode () func:

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

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

, , . Magento , - .

. _redirect() Mage_Core_Model_Url, URL- Url.

+9

Source: https://habr.com/ru/post/1782272/


All Articles