我迷失在 Zend Framework 的 url 重写中!我有一个route.ini
这样的:
routes.page.route = :slug
我在引导程序中有这样的电话:
protected function _initRoutes() {
$uri = explode('/', $_SERVER['REQUEST_URI']);
if (!in_array('admin', $uri)) {
//$front = Zend_Controller_Front::getInstance();
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
$router = $front->getRouter();
$router->addConfig($config, 'routes');
$front->registerPlugin(new Rez_Controller_Plugin_Routing(), 2);
}
}
插件是这样的:
class Rez_Controller_Plugin_Routing extends Zend_Controller_Plugin_Abstract {
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$item_db = new Application_Model_DbTable_Item();
if(NULL != $request->getParam("slug")){
if("admin" == $request->getParam("slug")){
$request->setModuleName('admin');
$request->setControllerName("index");
$request->setActionName('index');
}
$page = $item_db->getPage($request->getParam("slug"));
if(FALSE == $page){
$request->setModuleName('default');
$request->setControllerName($request->getParam("slug"));
$request->setActionName('index');
return;
}else{
if(NULL !== $request->getParam("language")){
$page["lang"] = $request->getParam("language");
}
$request->setModuleName('default');
$request->setControllerName("index");
$request->setActionName('page');
$request->setParams($page);
return;
}
}
}
问题是,只有当浏览器的语言为英语或用户单击英语标志时,我才必须在 URL 中添加语言前缀"htttp://mywebsite.com/en/a-simple-page"
,否则,URL 必须像"http://mywebsite.com/a-simple-page"
.
我试图在 route.ini 中添加它:
routes.page.route = :language/:slug
routes.page.reqs.language = "^(en|nl)$"
routes.page.defaults.language = "nl"
但是当我尝试"http://mywebsite.com/a-simple-page"
它在工作时不起作用"http://mywebsite.com/en/a-simple-page"
,我可以在插件中获取参数。即使语言代码不在 URL 中,如何使其接受所有 URL?