1

Suppose I have the following code.

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");
  }
}

Is it possible to achieve the output like the one in the last controller ? I am using zend framework 1.11 and are there any other solutions to achieve this functionality ?

In modules/module1/views/scripts/index/index.phtml, I have

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

And in 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 );

The output of the default module's index action is Nav2 link is printed 2 times. However, if the print a string instead of navigation, then the output is as desired like "Nav2" and "Nav1" sequentially.

h1m4l
  • 189
  • 3
  • 14

1 Answers1

1

Action View Helper will help you to accomplish this

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

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

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

But action view helper have several performance and debugging issues please see these links before deciding to use it

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

Community
  • 1
  • 1
Nandakumar V
  • 4,317
  • 4
  • 27
  • 47
  • Thanks for the answer and with your suggestion and In default module's controller I have added like $this->_helper->actionStack("index", "index", "module1"); and also for module2. This output is excellent. However, if I use Zend_Navigation($arrayData) in modules/module1/views/scripts/index/index.phtml and in modules/module2/views/scripts/index/index.phtml, the last actionStack is repeated. How can I use Zend_Navigation in view file with actionStack ? – h1m4l Sep 10 '13 at 13:06
  • what do u meant by " the last actionStack is repeated" ? – Nandakumar V Sep 11 '13 at 04:26
  • I have edited the problem and so you could understand the problem more clearly. – h1m4l Sep 11 '13 at 06:57
  • i am not sure about the cause of this issue... may be dispatch flow issue or handling multiple instance – Nandakumar V Sep 11 '13 at 07:42
  • can you check this ZF bug.. seems like this is the one you have http://framework.zend.com/issues/browse/ZF-6865 – Nandakumar V Sep 11 '13 at 07:43
  • 1
    The issue was solved using $this->navigation()->menu()->render($navigationContainerObject); Thanks Nandakumar. – h1m4l Sep 11 '13 at 09:14