1
votes

Does the ZF2 forward() controller plugin fire off a new request cycle? Or part thereof?

I am writing a ZF2 MVC application with widgetized content. The widgetized content is exposed via its own controller action because sometimes I need to hit it with ajax.

When I need to incorporate the widgetized content as a sub-view of another action (i.e. on a full page load), that action is using the forward() plugin to get the widgetized content. If it's going to introduce a significant overhead though I will go straight to the service layer instead (even though that approach is less DRY).

I realise that a performance test will answer this question for me, but I'm a few weeks away from being able to run such a test.

EDIT: when I say 'new request cycle', I mean the ZF2 MVC request cycle, i.e. route, dispatch, etc. Intuitively I would doubt it fires route a second time, but it could start the cycle from dispatch. I'm asking the question because I know that in ZF1 it triggered a who second cycle, which was a real performance drain.

1

1 Answers

0
votes

There are two options to "forward". Understand php is as server side language a processor to grab an incoming request and return a response.

That said, the first "forward" uses in-framework forwarding. This means there is only one request and one response. Internally the framework calls one controller action and then another one. Zend Framework calls this method forward.

The second "forward" is a real redirect, where the first response contains a Location header and the 302 http status code. This results in a second request and consecutively in a second response. Zend Framework calls this method redirect.

So with above, the forward you talk about in your question does not involve any sessions or route match parameters, since the second call to an action is within the same php process, so all variables are already known.

Is it possible to forward data to another controller/action in Zend 2?