如何在Zend 1.11中渲染不同控制器的不同动作的2个视图

时间:2012-09-17 11:47:11

标签: php zend-framework

我有两个控制器。

  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

  3. 但在我调用_forward后,read.phtml没有显示,我只能看到控制器业务的list.phtml。 我的问题是,如果我想同时调用控制器类别的read.phtml和控制器业务的list.phtml,我该怎么办?

3 个答案:

答案 0 :(得分:1)

转发前渲染当前操作:

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

答案 1 :(得分:0)

在read.phtml视图中,您可以使用:

echo $ this-> render('business / list.phtml');

显示其他视图。

答案 2 :(得分:0)

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

在布局中最近渲染它
$this->layout()->someOtherThanContent;