1

I am trying to redirect to a different controller from one controller . I also want to set an Url parameter along with the redirect. But this is throwing me an error

Uncaught Error: Call to undefined method Magento\Backend\Model\View\Result\Redirect\Interceptor::setParam()

Here is my code.

public function execute()
{

    $resultRedirect = $this->resultRedirectFactory->create();
    $resultRedirect->setPath('customer/index/new');
    $resultRedirect->setParam('myname', 'Nuno Sousa');
    return $resultRedirect;
}

What is wrong with the above code? or is there any other way?

  • What will be your result url? – Sukumar Gorai Oct 8 '18 at 13:34
  • it will go to create new customer page – Melvin Oct 8 '18 at 13:35
  • customer/index/new This is your custom page? – Sukumar Gorai Oct 8 '18 at 13:37
3

You can pass param like this :

$params = array('myname' => 'Nuno Sousa');
$resultRedirect->setPath('customer/index/new', ['params' => $params]);

You can retrive using this :

$this->getRequest()->getParams();
  • This worked . so easy – Melvin Oct 8 '18 at 13:37
  • 1
    Please accept answer :) – Rohan Hapani Oct 8 '18 at 13:38
  • So, It will useful for other developers. – Rohan Hapani Oct 8 '18 at 13:42
  • 1
    Happy to help !! Happy Coding :) – Rohan Hapani Oct 8 '18 at 14:06
  • @RohanHapani, how to link to controller from phtml with params? – jafar pinjar Jan 29 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.