Reputation: 499
I would like to include multiple views within a view in ZF2. I read this link: http://framework.zend.com/manual/current/en/modules/zend.view.quick-start.html
but there is a problem. In this way, I have to pass the values that are within a view, like this:
$secondView = new ViewModel (array('var1' => $var1 ......));
In this mode the controller and second action are bypassed. Is there a way to include a view without bypassing them? I would like variables to be passed from the second action controller, like an include php statement
Upvotes: 0
Views: 102
Reputation: 9008
If I understood correctly your question, I think that what you're asking is not possible.
My suggestion would be to move the retrieval of the data you need for the secondView somewhere else, away from the controller, and call it both from the second controller and form the first controller to pass them to the secondView.
If you really want to go on with your approach, the only possibility I see is to use javascript and ajax calls to retrieve the partials you need in your view
Upvotes: 1
Reputation: 785
You can use partials for that.
In your module.config.php under the 'view_manager' key you define a template map for your partial:
'view_manager' => array(
'template_map' => array(
'myPartial' => __DIR__ . '/../view/mymodule/partial/myPartial.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
Then in the view container you can use that partial using the partial() View Helper:
<div><?php echo $this->partial('myPartial', array('var1' => 'value1'); ?></div>
You can also pass variables to your partial. Those variables are referenced in your partial like any other view variable:
echo $var1;
Upvotes: 1