2012-09-17 86 views
2

我有2個控制器。如何在Zend中渲染2個不同控制器動作的視圖1.11

  1. CategoryController

    public function readAction() 
    { 
        $id = $this->_request->getParam('id'); 
        $categoryModel = new Model_Category(); 
        if(!$categoryModel) 
        { 
         throw new \Exception(__METHOD__.', could not create category model'); 
        } 
        $category = $categoryModel->getCategory($id); 
        $parent = $category->findParentRow(new Model_Category()); 
        if(!$parent) 
        { 
         $this->view->parent = 'no parent'; 
        } 
        else 
        { 
         $this->view->parent = $parent->name; 
        } 
    
        // I need to pass category object to read.phtml of controller category 
        // so that each attributes of the category could be displayed. 
        $this->view->category = $category; 
    
        // Below the category section, I also need to list all 
        // the business entities which are the child rows of that category. 
        // So I forward to controller business, action list. 
        // Normally I use list.phtml in controller business to do that. 
        $this->_forward('list', 'business'); 
    } 
    
  2. BusinessController

但之後我打電話_forward,該read.phtml不diplayed,我只能看到控制器業務的list.phtml。 我的問題是,如果我想同時調用控制器類別的read.phtml和控制器業務的list.phtml,我該怎麼辦?轉發之前

回答

1

渲染當前操作:

public function readAction() 
{ 
    // ... 
    $this->render(); 
    $this->_forward('list', 'business'); 
} 
+0

就是這樣;-)感謝你這麼多在佈局近來呈現它。 – varmansvn

0

在你read.phtml視圖中,您可以使用:

回聲$這個 - >渲染( '業務/ list.phtml');

顯示另一個視圖。

+0

這在我的情況下不起作用,因爲在我的列表視圖中,我還需要將排序,篩選和分頁控制放在那裏。我的意思是,我不需要渲染視圖,但也需要傳遞一些數據。總之,非常感謝你的迴應;-) – varmansvn

0

您可以使用$viewRenderer->setResponseSegment('someOtherThanContent')和使用

$this->layout()->someOtherThanContent; 
相關問題