We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

trying to make HTTP redirection with 3 parameters

I am trying to make an HTTP redirection for a route with 3 parameters and I have problems

My route:


$router->add("/panel/:controller/:action/:params",array(
    "module" => "panel",
    "controller" => 1,
    "action"     => 2,
    "params"     => 3,
))->setName("panel");

All options I have tried in my controller:


// generates /panel/index/index
return $this->response->redirect(array(
  'for' => 'panel',
  'controller' => 'index',
  'action' => 'index',
  0 => 'param1',
  1 => 'param2',
  2 => 'param3',
));

// generates /panel/index/index/Array
return $this->response->redirect(array(
  'for' => 'panel',
  'controller' => 'index',
  'action' => 'index',
  'params' => array(
    0 => 'param1',
    1 => 'param2',
    2 => 'param3',
)));

// generates /panel/index/index/Array
return $this->response->redirect(array(
  'for' => 'panel',
  'controller' => 'index',
  'action' => 'index',
  'params' => array(
    'param1',
    'param2',
    'param3',
)));

However:


// generates /panel/index/index/param1
return $this->response->redirect(array(
  'for' => 'panel',
  'controller' => 'index',
  'action' => 'index',
  'params' => 'param1'
));

//works but it is not what I need : /
return $this->dispatcher->forward(array(
  'for' => 'panel',
  'controller' => 'index',
  'action' => 'index',
  'params' => array('param1','param2','param3'),
));

Is it possible to make such a redirection?

TIA!

return $this->response-redirect(array(
    'for' => 'panel',
    'controller' => 'index',
    'action' => 'index',
    'params' => implode('/',$params_array)
    );

Maybe this?



26.3k

Thanks! Hehe, this is a solution! :)

But I would like to know if maybe this is a bug. This way I will be prepared to change the code when it will be fixed.

But also you can try like this

$router->add("/panel/:controller/:action/:params1/:params2/:params3",array(
    "module" => "panel",
    "controller"    => 1,
    "action"        => 2,
    "params1"       => 3,
    "params2"       => 4,
    "params3"       => 5
))->setName("panel");
return $this->response->redirect(array(
    'for' => 'panel',
    'controller' => 'index',
    'action' => 'index',
    'param1'    => 'some param',
    'param2'    => 'other param',
    'param3'    => 'thirrd param'
));


17.5k
return $this->response-redirect(array(
    'for' => 'panel',
    'controller' => 'index',
    'action' => 'index',
    'params' => '?'.implode('&=',$params_array)
    );