开发者

How to reencode url parameters with Zend Framework

开发者 https://www.devze.com 2022-12-17 04:48 出处:网络
I use the following code with my Zend Framework application: controller: $paramsOtherAction = $this->getRequest()->getParams();

I use the following code with my Zend Framework application:

controller:

$paramsOtherAction = $this->getRequest()->getParams();
$paramsOtherAction['action'] = 'otheractio开发者_JS百科n'
$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?).


Use the urlencode function:

foreach ( $paramsOtherAction as $key => $value )
{
    $paramsOtherAction[$key] = urlencode ( $value );
}


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

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

精彩评论

暂无评论...
验证码 换一张
取 消