我在Zend框架中有一个搜索动作。
,代码为:
function searchAction()
{
$keyword = $this->getRequest()->getParam('keyword');
if( !empty($keyword) )
{
//@todo here
}
}
我使用如下url将关键字发布到动作:
/索引/搜索/关键字/谷歌
:
- <
- 指数:控制器/gh><
- 搜索:行动/gh>
- 关键字,google:一对参数和值。
一切正常,直到用户搜索值为"/"字符的关键字
/索引/搜索/关键字//
=>: getParam('keyword')为空
我已经尝试使用%2F(它被"/"编码)
/索引/搜索/关键字/ % 2 f
=>: 404 Error
如何解决这个问题?
尝试简单使用:
$value = $this->_getParam('keyword');
你可以尝试在你的bootstrap.php中添加路由
$router = $frontController->getRouter();
$router->addRoute(
'searchOncontrollername',
new Zend_Controller_Router_Route('/controllername/search/:keyword', array('controller' => 'controllername',
'action' => 'search'
)));
之后你可以在控制器中使用变量关键字:
$keyword = $this->getRequest()->getParam("keyword");