Redirect method is defined in Magento controller interface

 * @var \Magento\Framework\App\Response\RedirectInterface
protected $_redirect;

So i am aware about that if i use controller Action then it will work.

But i want use specific model method to redirect the url

File location


and function goes like :

    public function Test(){

You can use below code for the redirect from the model.

Add below code as the parameter in the __construct method of your Model

\Magento\Framework\UrlInterface $url, 
\Magento\Framework\App\ResponseFactory $responseFactory,

Create object for both as below

$this->_url = $url;
$this->_responseFactory = $responseFactory;

Now, modify your function code.

public function Test()
   $CustomRedirectionUrl = $this->_url->getUrl('rbvendor/index/index');

Please let me know if you face any issue.

  • I recieved this error: - Error: Cannot instantiate abstract class Magento\Framework\Model\ResourceModel\AbstractResource in /var/www/html/wineconnection/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php – Kapil Dev Singh Dec 17 '20 at 13:16

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.