Reputation: 25
I just started at Zend Framework and i have some issues, When i use the URL function, which is inside a placeholder called "menu-gerenciador" that is in the "painel" layout, thats the default layout i use in the "painel" controller(/gerenciador/painel) it renders the right url:
this:
<a href="<?php echo $this->url(array("module" => "gerenciador", "controller" => "usuarios", "action" => "listar")); ?>">
Becomes this:
<a href="/gerenciador/usuarios/listar">
But when i click this link, i got redirected back to /gerenciador/painel
The directory of my application:
-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 Menu(witch is in a placeholder inside the painel layout(has the link)):
<?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() ?>
And Finally the Usuarios Controller where it should be redirected by the link:
<?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();
}
}
I already tried to put the reset param TRUE inside my URL function, but this dont work as well. I dont know why it keeps redirecting to the same page
Upvotes: 0
Views: 730
Reputation: 5740
In Usuarios Controller in the init method you have the line:
if($auth->hasIdentity()) {
Shouldnt that be:
if(!$auth->hasIdentity()) {
Otherwise logged in users are always redirected away from that controller
Upvotes: 1