0

我在 Zend Framework 应用程序中使用以下代码:

控制器:

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

看法:

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

这很好用,除非参数中有任何字符需要转义(编码),比如 url。我怎样才能以最好的方式编码这个参数数组?

编辑:

我实际上正在搜索的是将 a 参数传递给 url 函数的可能性,以确保我的 url 参数被编码(为什么这不是标准的呢?)。

4

2 回答 2

2

使用urlencode函数:

foreach ( $paramsOtherAction as $key => $value )
{
    $paramsOtherAction[$key] = urlencode ( $value );
}
于 2010-01-18T10:57:47.243 回答
2

转义参数的一种方法是使用 array_map 和 urlencode:

$paramsOtherAction = array_map('urlencode', $paramsOtherAction);
于 2010-01-18T11:31:58.440 回答