大佬教程收集整理的这篇文章主要介绍了基于标准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());
}
以上是大佬教程为你收集整理的基于标准PHP查询字符串的路由全部内容,希望文章能够帮你解决基于标准PHP查询字符串的路由所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。