2012-04-12 101 views
0

發送數據我想給從動作助手的一些數據,以局部而我無法做到這一點,以獲得清晰的圖像。這裏是我使用的所有相關代碼。從動作助手到局部視圖

在我layout.phtml我使用這個佔位符。生成onDemand導航菜單。

<?php echo $this->placeholder('action-navigation'); ?> 

因此,當我需要它在我的控制器或操作方法,我可以簡單地使用此代碼。

$this->_helper->navigation()->renderActionNavigation(); 

我正在使用的操作助手是。

class Zend_Controller_Action_Helper_Navigation extends Zend_Controller_Action_Helper_Abstract 
{ 
    private $_view = null; 

    public function direct() 
    { 
     $this->_view = $view = Zend_Layout::getMvcInstance()->getView(); 
     $this->_view->placeholder('action-navigation'); 
     return $this; 
    } 

    public function renderActionNavigation() 
    { 
     $config = new Zend_Config_Xml(
      APPLICATION_PATH.'/configs/navigation.xml', strtolower(
       $this->getRequest()->getControllerName(). 
       $this->getRequest()->getActionName() 
      ) 
     ); 
     $container = new Zend_Navigation($config); 

     // here i want to send $container to _action-navigation.phtml. 

     $this->_view->addScriptPath(APPLICATION_PATH.'/layouts/')->render('partials/_action-navigation.phtml'); 
    } 
} 

這是我的看法偏_action-navigation.phtml

$this->placeholder('action-navigation')->captureStart(); 

//i want to get zend_navigation instance. from the above action helper here. 

$this->placeholder('action-navigation')->captureEnd(); 

我有問題發送從動作助手數據,以局部視圖_action-navigation.phtml我該怎麼做呢?

謝謝。

回答

1

使用partial()代替render()

$this->_view->partial('partials/_action-navigation.phtml', array('nav' => $container)); 

而在你的部分:

$this->nav // to get your container 
+0

它的工作原理。非常感謝你@Liyali :) – 2012-04-12 13:22:18