Zend Framework - 重定向到路由方向

时间:2013-03-30 10:24:22

标签: php zend-framework

PHP Zend Framework存在一个小问题。 我在文件application.ini中有以下路由:

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');

然后我将重定向到地址: my-project / public / index / index 但我希望地址为 my-project / public / main-page.html (因为它确定了application.ini)

有人能帮助我吗? 附: 抱歉我的英文。

2 个答案:

答案 0 :(得分:1)

使用Redirector helper

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

对于您的情况,结果如下:

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

答案 1 :(得分:-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只能路由到项目中的控制器。

如果是这样,您只需添加以下内容即可重定向:

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