1

In magento 2.0.7 how we can make redirect our custom module system config after successfully saved data

For example want to redirect one particular section

1
<?php
 namespace [Vendor]\[modulename]\Observer;
 use Magento\Framework\Event\ObserverInterface;

class [YourClass] implements ObserverInterface
{
protected $_responseFactory;
protected $_url;

public function __construct(

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

public function execute(Observer $observer) {
    $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface'); 
    $currentStoreId = $storeManager->getStore()->getId();
    $currentWebsiteId = $storeManager->getStore()->getWebsiteId();
    $RedirectUrl= $this->_url->getUrl('*/*/edit', array('_current' => array('section name here', 'website here', 'store here)));
    $this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
    die();
}
}

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.