如何从不同的控制器调用多个模块的多个动作并组合输出?

时间:2013-09-10 08:43:39

标签: php zend-framework

假设我有以下代码。

class Module1_IndexController extends Zend_Controller_Action {
  public function indexAction() {
    $this->view->data1 = "This is module1's index action view";
  }
}

class Module2_IndexController extends Zend_Controller_Action {
  public function indexAction() {
    $this->view->data2 = "This is default module2's index action view";
  }
}

class Default_IndexController extends Zend_Controller_Action {
  public function indexAction() {
    // $module1_output = Call Module1_IndexController's indexAction view output
    // $module2_output = Call Module2_IndexController's indexAction view output

    $this->_helper->actionStack("index", "index", "module1");
    $this->_helper->actionStack("index", "index", "module2");
  }
}

是否可以像上一个控制器中那样实现输出?我正在使用zend framework 1.11,还有其他解决方案来实现这个功能吗?

modules / module1 / views / scripts / index / index.phtml 中,我有

$module1NavArray = array(
        array( 'label' => 'Nav1', 'uri' => '/home/module1/nav1' )
);
$container = new Zend_Navigation($module1NavContainer);
print $this->navigation( $container );

modules / module2 / views / scripts / index / index.phtml

$module2NavArray = array(
        array( 'label' => 'Nav2', 'uri' => '/home/module2/nav2' )
);
$container = new Zend_Navigation($module2NavContainer);
print $this->navigation( $container );

默认模块的索引操作的输出是Nav2链接打印2次。但是,如果打印字符串而不是导航,那么输出就像“Nav2”和“Nav1”顺序一样。

1 个答案:

答案 0 :(得分:1)

Action View Helper将帮助您完成此操作

modules / default / views / scripts / index / index.phtml

<?php echo $this->action('index', 'index', 'module1')); ?>

<?php echo $this->action('index', 'index', 'module2'); ?>   

但是动作视图助手有几个性能和调试问题,请在决定使用它之前查看这些链接

How can I speed up calls to the action() view helper?
Action View Helper in Zend - Work around?
Using Action Helpers To Implement Re-Usable Widgets