0

Zend Framework を使い始めたばかりで、いくつかの問題があります。「painel」レイアウトにある「menu-gerenciador」というプレースホルダー内にある URL 関数を使用すると、「painel」で使用するデフォルトのレイアウトになります。 controller(/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

パイネルコントローラー:

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 コントローラー:

<?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();    
    }


}

URL 関数内にリセット パラメータ TRUE を入れようとしましたが、これもうまくいきません。同じページにリダイレクトし続ける理由がわかりません

4

1 に答える 1

1

init メソッドの Usuarios Controller には、次の行があります。

if($auth->hasIdentity()) {

それはすべきではありません:

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

それ以外の場合、ログインしているユーザーは常にそのコントローラーからリダイレクトされます

于 2012-08-14T23:31:02.360 に答える