Zend Framework - 重定向到路由方向
问题描述:
我有一个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. 对不起,我的英语。
答
使用gotToUrl方法对于您的情况下,这个结果:
如果是这样,你可以简单地添加以下重定向
$this->_redirector->gotoRoute(array(), 'mainpage');
答
首先,你的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');
谢谢你!有用 : ) – klapaucius