2013-03-30 175 views
1

我有一个PHP Zend Framework的小问题。 我在文件的application.ini以下路线:Zend Framework - 重定向到路由方向

resources.router.routes.mainpage.route = "main-page.html" 
resources.router.routes.mainpage.defaults.controller = "index" 
resources.router.routes.mainpage.defaults.acion = "index" 

如果我在任何诉讼直接做:

$this->_helper->redirector('index', 'index'); 

的话,我会重定向到地址:我的项目/公/指数/指数 但我想解决是我的项目/公共/主page.html中(因为它是确定的application.ini)

能如此人帮助我? P.S. 对不起,我的英语。

回答

1

使用gotToUrl方法对于您的情况下,这个结果:

如果是这样,你可以简单地添加以下重定向

$this->_redirector->gotoRoute(array(), 'mainpage'); 
+0

谢谢你!有用 : ) – klapaucius

-2

首先,你的application.ini中的语法似乎是错误的。见ZF-Manual: Resource Router

在你的情况下,它会是。像:

resources.router.routes.mainpage.route = "/index" 
resources.router.routes.mainpage.defaults.controller = "index" 
resources.router.routes.mainpage.defaults.acion = "MainPage" 

但是,它似乎你正试图重定向到静态页面,这不是ZF的一部分。就我所知,Zend_Controller_Router只能路由到您的项目中的控制器。从Redirector helper

$this->_redirector = $this->_helper->getHelper('Redirector'); 
$this->_redirector->gotoRoute(
     array('fooRouteArgument' => fooValue), 
     'route-name' 
); 

//In view-scripts: 
<?php echo $this->baseUrl('main-page.html'); ?> 
//In controllerActions: 
$this->_helper->getHelper('Redirector') 
     ->gotoUrl('/main-page.html'); 
+0

让我建议您阅读手册,因为您的答案完全错误。路由的主要目标是将其用作路由名称的路径别名。 – Maks3w

+0

谢谢,但路线的目标对我来说很清楚。我明白user2225468的主要问题是,她/他想要建立到静态页面的路由而不是控制器操作。另外,他将'resources.router.routes.mainpage.route'设置为路由应该到达的地方。但是'resources.router.routes.mainpage.route'应该有哪个路由器变为活动的规则。 – mdthh