title: ZF2: How to pass parameters to forward plugin which I can then get in the method I forward them to?
body: <p>I have an Action method in <strong>Foo</strong> Controller which requires parameters:</p>
  
  <pre><code>public function fooAction($one, $two) {
      $a = one;
      $b = $two;
  }
  </code></pre>
  
  <p>And I need to forward to that method from the other method of some <strong>Boo</strong> Controller. And one of those parameters has to be by reference parameter. The only example that <a href="http://zf2.readthedocs.org/en/latest/modules/zend.mvc.plugins.html#the-forward-plugin" rel="nofollow noreferrer">the manual</a> has is this:</p>
  
  <pre><code>$result = $this-&gt;forward()-&gt;dispatch('Boo\Controller\Boo', array('action' =&gt; 'boo'));
  </code></pre>
  
  <p>No any additional parameters. But they write:</p>
  
  <blockquote>
    <p>$params is an optional array of parameters with which to see a
    RouteMatch object for purposes of this specific request.</p>
  </blockquote>
  
  <p>So, I tried:</p>
  
  <pre><code>$result = $this-&gt;forward()-&gt;dispatch('Boo\Controller\Boo', array(
                                                        'action' =&gt; 'boo',
                                                        'one' =&gt; &amp;$one,
                                                        'two' =&gt; $two,
                                                   ));
  </code></pre>
  
  <p>But it doesn't work.</p>
  
  <p>Is there any way to pass additional parameters to forward controller? </p>
  
  <p><strong>UPD:</strong></p>
  
  <p>These do not work too:</p>
  
  <pre><code>$result = $this-&gt;forward()-&gt;dispatch('Boo\Controller\Boo', array(
                                                        'action' =&gt; 'boo',
                                                        'params' =&gt; array(
                                                            'one' =&gt; &amp;$one,
                                                            'two' =&gt; $two,
                                                       )));
  
  
  $result = $this-&gt;forward()-&gt;dispatch('Boo\Controller\Boo', array(
                                                        'action' =&gt; 'boo',
                                                        'options' =&gt; array(
                                                            'one' =&gt; &amp;$one,
                                                            'two' =&gt; $two,
                                                       )));
  </code></pre>
  
  <p><strong>UPD 2:</strong></p>
  
  <p>I still can't get the functionality I want (to pass parameters with the <code>forward</code> plugin) but I found other solutions. Before calling the <code>forward</code> plugin I set the variables to the <code>Request</code> object and after the <code>forward</code> I get them from the <code>Request</code> in my <strong>boo</strong> Action of my <strong>Boo\Controller\BooController</strong>:</p>
  
  <pre><code>// in Foo::fooAction
  $this-&gt;getRequest()-&gt;one = &amp;$one;
  $this-&gt;getRequest()-&gt;two = $two;
  $result = $this-&gt;forward()-&gt;dispatch('Boo\Controller\Boo', array('action' =&gt; 'boo'));
  
  // in Boo::booAction
  $a = $this-&gt;getRequest()-&gt;one;
  $b = $this-&gt;getRequest()-&gt;two;
  </code></pre>
  
  <p>Stupid solution, it will not work with Ajax requests. Still interested how to pass parameters with the forward plugin. OR MAYBE how to get them in the <strong>booAction</strong>. Because there in no anything in the <code>Request</code> if I pass them with the <code>forward</code>.</p>
  
  <p><strong>UPD 3 and Final:</strong></p>
  
  <p>I finally found where they've decided to hide parameters I pass with the <code>forward</code> plugin. They put them in the <code>RouteMatch</code> object.</p>
  
  <p>- Tryyyy to guess where we've hidden your params... Oh yeeah, they are in the <code>RouteMatch</code>, of course they are there, didn't you think smth else?</p>
  
  <p>And NO ANY info in the <code>forward</code> plugin section of the manual!</p>
  
  <p>To get params, I have to do this in my <code>BooController::booAction</code>:</p>
  
  <pre><code>$param = $this-&gt;getEvent()-&gt;getRouteMatch()-&gt;getParam('nameOfParam');
  </code></pre>