1

I have a small problem with PHP Zend Framework. I have the following routes in file application.ini:

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

If i do a direct in any action:

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

then i will be redirect to adress: my-project/public/index/index But i want to adress be a my-project/public/main-page.html (as it is determined application.ini)

Can somebody help me? P.S. Sorry for my english.

4

2 回答 2

1

使用重定向器助手中的 gotToUrl 方法

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

对于您的情况,这会导致:

$this->_redirector->gotoRoute(array(), 'mainpage');
于 2013-03-30T16:33:05.970 回答
-2

First of all, it seems your syntax in your application.ini is wrong. See ZF-Manual: Resource Router

In your case it would bes sth. like:

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

However, it seems you're trying to redirect to a static page, which is not part of ZF. Zend_Controller_Router can only route to Controllers within your project, as far as I know.

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

//In view-scripts:
<?php echo $this->baseUrl('main-page.html'); ?>
//In controllerActions:
$this->_helper->getHelper('Redirector')
        ->gotoUrl('/main-page.html');
于 2013-03-30T16:24:40.790 回答