我刚开始使用 Zend Framework,我遇到了一些问题,当我使用 URL 函数时,它位于“painel”布局中名为“menu-gerenciador”的占位符内,这是我在“painel”中使用的默认布局控制器(/gerenciador/painel)它呈现正确的网址:
这:
<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();
}
}
我已经尝试将重置参数 TRUE 放在我的 URL 函数中,但这也不起作用。我不知道为什么它一直重定向到同一页面