标签:zend-route zend-framework php
如您所知,Zend Framework(v1.10)使用基于斜杠分隔参数的路由,例如.
[server]/controllerName/actionName/param1/value1/param2/value2/
Queston是:如何强制Zend Framework使用标准PHP查询字符串检索动作和控制器名称,在这种情况下:
[server]?controller=controllerName&action=actionName¶m1=value1¶m2=value2
我试过了:
protected function _initRequest()
{
// Ensure the front controller is initialized
$this->bootstrap('FrontController');
// Retrieve the front controller from the bootstrap registry
$front = $this->getResource('FrontController');
$request = new Zend_Controller_Request_Http();
$request->setControllerName($_GET['controller']);
$request->setActionName($_GET['action']);
$front->setRequest($request);
// Ensure the request is stored in the bootstrap registry
return $request;
}
但这对我不起作用.
解决方法:
$front->setRequest($request);
该行仅设置Request对象实例. frontController仍然通过路由器运行该请求,在该路由器中该请求被分配了要调用的控制器/动作.
您需要创建自己的路由器:
class My_Router implements Zend_Controller_Router_Interface
{
public function route(Zend_Controller_Request_Abstract $request)
{
$controller = 'index';
if(isset($_GET['controller'])) {
$controller = $_GET['controller'];
}
$request->setControllerName($controller);
$action = 'index';
if(isset($_GET['action'])) {
$action = $_GET['action'];
}
$request->setActionName($action);
}
}}
然后在您的引导程序中:
protected function _initRouter()
{
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->setRouter(new My_Router());
}
标签:zend-route,zend-framework,php 来源: https://codeday.me/bug/20191106/2000999.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。