2011-05-13 58 views
2

我有一個控制器與一些視圖/行動。我正在使用zend_navigation和麪包屑作爲主導航。但是,當某些視圖/操作呈現時,我想在本組視圖/操作中添加一個帶有本地導航的「控制面板」。添加面板是沒有問題是決定哪些視圖/動作我在邏輯。更改相同控制器下不同視圖中的佈局 - zend框架

我的ID從控制器級視圖/行動

$controller = $this->getRequest()->getControllerName(); 
    $action = $this->getRequest()->getActionName(); 

但我可以傳遞到佈局,還是我需要或可以檢測到我在佈局中的位置? 我想有一個選擇是在一個單獨的控制器中使用控制面板創建視圖,但這似乎是一個愚蠢的做法。

回答

1

我認爲你必須要組合的ArneRie和Acherer說:

內/application/configs/cp.ini:

cp[] = "moduleA.controllerB.actionC" 
cp[] = "moduleA.controllerD.actionE" 

內,您的引導:

protected function _initCp() 
{ 
    $ini = new Zend_Config_Ini(APPLICATION_PATH . '/configs/cp.ini'); 
    Zend_Registry::set('cp', $ini->toArray()); 
} 

內部佈局:

<?= $this->partial('cp.phtml') ?> 

在你的部分:/application/layouts/cp.phtml:

<?php 
$request = Zend_Controller_Front::getInstance()->getRequest(); 
$module = $request->getModuleName(); 
$controller = $request->getControllerName(); 
$action = $request->getActionName(); 
if (in_array(implode('.', array($module, $controller, $action)), Zend_Registry::get('cp')) : ?> 
    // display cp html here 
<?php endif ?> 

您可能要仔細檢查ini陣列,但這是Zend Jedi的路徑:p

+0

對於部分甚至更清潔的人來說是+1 – Ascherer 2011-05-15 16:55:52

0

只是一個想法,我會做一個ControllerPlugin

public function preDispatch() 
{ 
    $controller = $this->getRequest()->getControllerName(); 
    $action = $this->getRequest()->getActionName(); 

    $layout = Zend_Layout::getMvcInstance(); 
    $layoutView = $layout->getView(); 

    $whereIam = $controller. '.' .$action; 

    switch ($whereIam) { 
     case 'index.showuser': 
      $layoutView->showPanel = true; 
      $layoutView->controlPanel = $this->view->render('myPanel.phtml'); 
      break; 
     default: 
      break; 
    } 
} 


    //layout.phtml 
    if ($this->showPanel === true) { 
     echo $this->controlPanel; 
    } 
0

可以工作,或只是路過就需要它的行動$this->view->cp = true;內,而且在layout.phtml文件進行檢查,看如果將其設置和真正的