views:

18

answers:

1

I call an action helper in one of my views using the following code

echo $this->action('foo', 'bar');

The fooAction in the barController does its thing and outputs a list of pages. However, the list has the layout in the output again, which is mightily irritating. If I disable the layout in the fooAction, this causes layout to be completely disabled on the live side, as well.

I'm vexed. I could just create a view helper, and there are many ways around this, but out of curiousity I was wondering if anyone had a solution to this.

A: 

From the ZF Reference Guide on Action ViewHelper

The API for the Action view helper follows that of most MVC components that invoke controller actions: action($action, $controller, $module = null, array $params = array()). $action and $controller are required; if no module is specified, the default module is assumed.

Modify your controller to accept a param that controls whether the action should disable the layout. When using the action helper, pass this control flag.

On a sidenote: using the Action ViewHelper is considered bad practise as it will go through the entire dispatch process again and this will slow down your app. If possible, try to access the model directly.

Gordon