I have created a custom grid in the admin panel using UI components. Everything is working fine except that there is no success/error message shown on the grid page.
If I redirect the controller after saving action to the edit record page, it shows the success/error message.
I have also tried to redirect to some other grid after saving the data, and the message is being shown correctly there.
I have matched almost everything of my grid with another working grid, but could not find any clue yet.
Can anyone help me out to find the problem?
Please let me know if you need to see the code.
Update: Added code below.
Grid Controller (Which has problem):
<?php
namespace Stack\RuleBasedDiscount\Controller\Adminhtml\Rules;
class Index extends \Magento\Backend\App\Action
{
const ADMIN_RESOURCE = 'Stack_RuleBasedDiscount::rules';
protected $resultPageFactory;
public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
$this->_view->loadLayout();
$this->_setActiveMenu('Stream_RuleBasedDiscount::rules');
$this->_addBreadcrumb(__('Rule Based Discount'), __('Rule Based Discount'));
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__('Rule Based Discount'));
return $resultPage;
}
}
Save Controller:
<?php
namespace Stack\RuleBasedDiscount\Controller\Adminhtml\Rules;
class Saveedit extends \Magento\Backend\App\Action {
protected $_ruleModel;
protected $_storeManager;
public function __construct(
\Magento\Backend\App\Action\Context $context, \Stack\RuleBasedDiscount\Model\Rule $ruleModel, \Magento\Store\Model\StoreManagerInterface $storeManager
) {
$this->_ruleModel = $ruleModel;
$this->_storeManager = $storeManager;
parent::__construct($context);
}
public function execute() {
try {
$data = $this->getRequest()->getParams();
$this->_ruleModel->setData($data);
$this->_ruleModel->save();
$message = __('Rule information has been saved successfully.');
$this->messageManager->addSuccess($message);
$this->_redirect('rulebaseddiscount/rules/index');
return;
} catch (\Exception $e) {
$message = __('There was some problem in saving rule information. Please try again later.');
$this->messageManager->addError($message);
$this->_redirect($this->_redirect->getRefererUrl());
return;
}
}
}