基于标准 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;
}
但它对我不起作用。
As you know, Zend Framework (v1.10) uses routing based on slash separated params, ex.
[server]/controllerName/actionName/param1/value1/param2/value2/
Queston is: How to force Zend Framework, to retrive action and controller name using standard PHP query string, in this case:
[server]?controller=controllerName&action=actionName¶m1=value1¶m2=value2
I've tried:
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;
}
But it doesn't worked for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该行仅设置 Request 对象实例。 frontController 仍然通过路由器运行请求,在路由器中它被分配要调用的控制器/操作。
您需要创建自己的路由器:
然后在引导程序中:
The line only sets the Request object instance. The frontController still runs the request through a router where it gets assigned what controller / action to call.
You need to create your own router:
Then in your bootstrap:
您是否尝试过:
$router->removeDefaultRoutes()
,然后$request->getParams()
或$request->getServer()
代码>?Have you tried:
$router->removeDefaultRoutes()
, then$request->getParams()
or$request->getServer()
?