0

I use the following code with my Zend Framework application:

controller:

$paramsOtherAction = $this->getRequest()->getParams();
$paramsOtherAction['action'] = 'otheraction'
$this->view->paramsOtherAction = $paramsOtherAction;

view:

<a href="<?php echo $this->url($this->paramsOtherAction)?>"> Do other action with same params </a>

This works fine, except when there are any characters in the parameters that need to be escaped (encoded), like url's. How can I in the best way encode this array of parameters?

Edit:

What I am searching actually is the possibility to pass the a parameter to the url function that makes sure that my url-parameters are encoded (why isn't that done standard anyway?).

2
  • Why don't you modify the url method to do the escaping? Commented Jan 18, 2010 at 23:18
  • The url helper, is part of the Zend_View. I can of course make a new helper (extending the old one), but this is such a common use case that I would expect that Zend can do this already. Commented Jan 19, 2010 at 6:31

2 Answers 2

2

Use the urlencode function:

foreach ( $paramsOtherAction as $key => $value )
{
    $paramsOtherAction[$key] = urlencode ( $value );
}
Sign up to request clarification or add additional context in comments.

1 Comment

I guess an array_map('urlencode',$array) would even be better... Maybe I add this as an answer myself
2

One way of escaping the parameters is to use array_map and urlencode:

$paramsOtherAction = array_map('urlencode', $paramsOtherAction);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.