2

我有2个控制器。

  1. 类别控制器

    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. 业务控制器

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

4

3 回答 3

1

转发前渲染当前动作:

public function readAction()
{
    // ...
    $this->render();
    $this->_forward('list', 'business');
}
于 2012-09-17T12:54:53.407 回答
0

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

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

显示另一个视图。

于 2012-09-17T12:55:03.230 回答
0

您可以$viewRenderer->setResponseSegment('someOtherThanContent')在最近的布局中使用和渲染它

$this->layout()->someOtherThanContent;
于 2012-09-17T13:35:11.767 回答