Zend View Helper功能URL重定向到错误的控制器

时间:2012-08-14 21:08:48

标签: zend-framework

我刚刚开始使用Zend Framework,我遇到了一些问题, 当我使用URL函数时,它位于“painel”布局中名为“menu-gerenciador”的占位符内,这就是我在“painel”控制器(/ gerenciador / painel)中使用的默认布局,它呈现了正确的URL :

这样:

<a href="<?php echo $this->url(array("module" => "gerenciador", "controller" => "usuarios", "action" => "listar")); ?>">

成为这个:

<a href="/gerenciador/usuarios/listar">

但是当我点击此链接时,我被重定向回/ gerenciador / painel

我的申请目录:

-application
--configs
--forms
--layouts
--modules
---default
----controllers
-----IndexController
-----LoginController
----models
----views
---gerenciador
----controllers
-----PainelController
-----UsuariosController
----models
----views
-data
-public
-library
-tests

Painel Controller:

class Gerenciador_PainelController extends Zend_Controller_Action
{

public function init()
{
    $this->_helper->layout->setLayout('painel'); 

    $auth = Zend_Auth::getInstance();

    if(!$auth->hasIdentity()) {
        $this->_redirect($this->view->url(array('module' => 'default', 'controller' => 'login')));
    }

    $this->view->usuario = $auth->getIdentity();
}

public function preDispatch()
{
    $this->view->render('painel/menu.phtml');
}

public function indexAction()
{

}

public function logoutAction() 
{
    $auth = Zend_Auth::getInstance();
    $auth->clearIdentity();

    $this->_redirect($this->view->url(array('module' => 'default', 'controller' => 'index', 'action' => 'index')));       
}


}

Painel菜单(女巫位于painel布局内的占位符(有链接)):

<?php $this->placeholder('menu-gerenciador')->captureStart() ?>

<div id="menu-painel">
    <h3><a href="#">Gerenciador</a></h3>
    <div>
        <ul class="menulista">
            <a href="<?php echo $this->url(array("module" => "gerenciador", "controller" => "painel")); ?>">
                <li>Inicial</li>
            </a>
            <a href="<?php echo $this->url(array("module" => "gerenciador", "controller" => "usuarios", "action" => "listar")); ?>">
                <li>Usuarios</li>
            </a>
            <li>Banner</li>
            <li>Pagina Empresa</li>
            <li>Configuracoes</li>
        </ul>
    </div>
</div>

<?php $this->placeholder('menu-gerenciador')->captureEnd() ?>

最后是Usuarios Controller应该通过链接重定向:

<?php

class Gerenciador_UsuariosController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->layout->setLayout('painel');

        $this->view->headLink()->appendStylesheet($this->view->baseUrl('css/bootstrap/bootstrap.css'));

        $auth = Zend_Auth::getInstance();

        if($auth->hasIdentity()) {
            $this->_redirect($this->view->url(array('module' => 'default', 'controller' => 'login'), null, TRUE));
        }
    }

    public function indexAction()
    {
        $this->_redirect($this->view->url(array(
            "module"     => "gerenciador",
            "controller" => "usuarios",
            "action"     => "listar"
        )));
    }

    public function listarAction()
    {
        $model = new Gerenciador_Model_Usuario();

        $this->view->listaUsu = $model->listar();    
    }


}

我已经尝试将重置参数TRUE置于我的URL函数中,但这也不行。 我不知道为什么它会重定向到同一页面

1 个答案:

答案 0 :(得分:1)

在init方法的Usuarios Controller中,您有以下行:

if($auth->hasIdentity()) {

不应该是:

if(!$auth->hasIdentity()) {

否则,登录用户始终会从该控制器重定向