0

I tried below code but page is not redirecting

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$redirect = $objectManager->get('\Magento\Framework\App\Response\Http');
$redirect->setRedirect('Your path....');

Please, anyone help me.

1
  • what issue your are facing ?
    – Yogesh
    Feb 15, 2018 at 14:24

2 Answers 2

1

You need to define constructor for it.

Below code is working for me.

Vendor/Package/Model/Plugin/Form.php

<?php 
namespace Vendor\AdvancedReviews\Model\Plugin;

class Form
{
protected $_responseFactory;
protected $_url;

public function __construct(

    \Magento\Framework\App\ResponseFactory $responseFactory,
    \Magento\Framework\UrlInterface $url
) {
    $this->_responseFactory = $responseFactory;
    $this->_url = $url;
}



public function afterexecute(\Magento\Customer\Controller\Adminhtml\Group\Save $save,$result)
{
           // Do your stuff
}

$CustomRedirectionUrl = $this->_url->getUrl('*/*/');
    $this->_responseFactory->create()->setRedirect($CustomRedirectionUrl)->sendResponse();
    exit();
1
  • It's not working. I need redirect is working .phtml file ? Feb 15, 2018 at 10:30
1

If you are doing custom redirection from Controller, you can use the below code:

$url = $this->_url->getUrl('customer/account/create'); //custom path URL
$this->getResponse()->setRedirect($url);
return;

If you want to do custom redirection using object manager, you can use the below code:

$response = $this->_objectManager->get("\Magento\Framework\App\ResponseInterface");
$url = $this->_objectManager->get("\Magento\Framework\UrlInterface");

$url = $this->_url->getUrl('customer/account/create'); //custom path URL
$response->setRedirect($url);
return; 
1
  • what is _url? i get error Undefined property Dec 30, 2019 at 13:17

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.