Php 路由URL以特殊字符开头
在ZendFramework中,我想将以Php 路由URL以特殊字符开头,php,zend-framework,url,url-routing,Php,Zend Framework,Url,Url Routing,在ZendFramework中,我想将以~开头的URL路由到特殊的控制器和操作,以便其他URL不能以~开头正常工作 例如,请参见以下两个url路由: mysite.com/~user 及 我怎样才能做到这一点呢?不确定zend的具体情况,但他们最好的方法是在url路由器开始工作之前添加一个哈希查找表 假设mod_rewrite转换为: mysite.com/~user 为此: mysite.com/index.php?路径=~user 然后你会这样做: $path = $_GET['path'
~
开头的URL路由到特殊的控制器和操作,以便其他URL不能以~
开头正常工作
例如,请参见以下两个url路由:
mysite.com/~user
及
我怎样才能做到这一点呢?不确定zend的具体情况,但他们最好的方法是在url路由器开始工作之前添加一个哈希查找表 假设mod_rewrite转换为: mysite.com/~user 为此: mysite.com/index.php?路径=~user 然后你会这样做:
$path = $_GET['path'];
$url_mod = array(
'~user'=>'my_other_controller',
'admin'=>'my_other_controller',
);
if(isset($url_mod[$path)) {
$path = $url_mod[$path];
}
试着在你的引导中使用它
// Get the instance of the router
$router = Zend_Controller_Front::getInstance()->getRouter();
// Set up a new regex router to match routes starting with ~
$route = new Zend_Controller_Router_Route_Regex(
'(^\~)',
//This route should use a 'special' controller
array(
'controller' => 'special',
'action' => 'index'
)
);
// Add the new route to the router
$router->addRoute('archive', $route);
您需要一个名为
Special
的控制器来响应通过此路由器路由的请求。请注意,我需要一个路由URL
或我可以在ZendFramework中使用的任何方法。我尝试了一下,错误消息是指定的控制器无效(~user)
。
// Get the instance of the router
$router = Zend_Controller_Front::getInstance()->getRouter();
// Set up a new regex router to match routes starting with ~
$route = new Zend_Controller_Router_Route_Regex(
'(^\~)',
//This route should use a 'special' controller
array(
'controller' => 'special',
'action' => 'index'
)
);
// Add the new route to the router
$router->addRoute('archive', $route);