0

I have two modules

1)Paypalrec with action fornt - Index/Index

2) unsubscribe with action admin/Index/UnsubscribeFinal

I want to redirect Index/Index controller to admin/Index/UnsubscribeFinal here.

Can anyone help?

2

1 Answer 1

0

To do the following in Magento 2, you must do the following in your execute method:

public function execute()
{
    /* Do your controller action stuff here */
    $resultRedirect = $this->resultRedirectFactory->create();
    $resultRedirect->setPath('adminRouteFrontName/controllerFolder/actionClass');
    return $resultRedirect;
}

You don't need to add the \Magento\Framework\Controller\Result\RedirectFactory to your constructor as it is already declared in the abstract class Magento\Framework\App\Action\AbstractAction so you have already access to the $this->resultRedirectFactory variable.

The parameters in my example are:

  • adminRouteFrontName: declared in your adminhtml/routes.xml
  • controllerFolder: name of the controller folder under Controller/Adminhtml
  • actionClass: name of your action class under the controller folder for example with Index.php it would be index, for Grid.php it would be grid and so on.
2
  • i have tried but it's redirect me to front side Jun 21, 2018 at 8:13
  • I want redirect front to backend not backend to front Jun 21, 2018 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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