How to forward data to another action using Forward Plugin and read it there in Zend Framework 2?

178 Views Asked by At

I have two actions in a controller: actionA() and actionB(). Dependent on a condition the actionA() should return a ViewModel object or be forwarded to actionB() (and return its result):

class MyController extends AbstractActionController {

public function aAction() {
    ...
    $data = ...
    ...
    if (...) {
        $result = new ViewModel(array(
            'data' => $data,
        ));
    } else {
        $result = $this->forward()->dispatch('MyModule\Controller\My', array(
            'action' => 'b',
        ));
    }
    return $result;
}

I tried it with

        $result = $this->forward()->dispatch('MyModule\Controller\My', array(
            'action' => 'b',
            'data' => $data,
        ));

But I have no idea, how to fetch this data now.

I'm sure, it's possible. How can I do it?

1

There are 1 best solutions below

0
On
    public function bAction() {
        ...
        // so:
        $params = $this->params()->fromRoute();
        // or so:
        $params = $this->getEvent()->getRouteMatch()->getParams();
        ...
    }