如何解决用户浏览index.php时的情况
作者:互联网
在Zend框架中,使用MVC,如果A用户明确地浏览到http://base/url/index.php而不是http://base/url,系统认为真正的基本URL是http://base/url/index.php/,并根据它计算系统中的所有URL.
所以,如果我有一个控制器XXX和行动YYY链接将是
http://base/url/index.php/XXX/YYY这当然是错的.
我目前通过在index.php添加一行来解决这个问题:
$_SERVER["REQUEST_URI"]=str_replace('index.php','',$_SERVER["REQUEST_URI"]);
我想知道ZF中是否有内置方法来解决这个问题.
解决方法:
您可以使用Zend_Controller_Router_Route_Static
(p!)来使用ZF执行此操作,例如:
阅读上面链接的手册页,有一些很好的例子可以找到.
$route = new Zend_Controller_Router_Route_Static(
'index.php',
array('controller' => 'index', 'action' => 'index')
);
$router->addRoute('index', $route);
不能说我完全不同意你的做法.也就是说,其他人可能会指出5000左右的缺点.祝你好运.
标签:php,zend-framework,zend-framework-mvc 来源: https://codeday.me/bug/20190724/1520167.html