passing variable from one controller to another

I want to pass a variable from one controller to another which should be eventually passed to the view. Unfortunately using return $this->forward('controllerB/actionB'); from controllerA where controllerB/actionB has a variable that needs to be passed to the view is not passed.

What is the best way to route variables from controllers to controller and finally to view ?


Hi, i am using the dispatcher and forward

        "action" => "search",
        "params" => array(1, 2, 3)

docs :

about views, i am using

//from the cotroller

    'name' => 'koko'
    'age' => 16

//inside the view

echo $this->view->name; //prints koko

return $this->dispatcher->forward([
        "controller" => "controllerB"
        "action" => "actionB",
        "params" => [
// Get params in controllerB / actionB
$params = $this->dispather->getParam("param1"); // use getParams() to get all parameters