문제

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?

도움이 되었습니까?

해결책

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();

다른 팁

I am using Magento 2.3.4

$params = array('myname' => 'Nuno Sousa');

Somehow this did not work for me.

$resultRedirect->setPath('[modulename]/[controllername]/[actionname]', ['params' => $params]);

This worked.

$resultRedirect->setPath('[modulename]/[controllername]/[actionname]', $params);

Just in case if anyone having this same issue

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top