0

Success Message Not Display

In Controller :-

public function execute()
{

      $delid = $this->getRequest()->getParam('id');

      try{
         $user = $this->_userFactory->create();
         $user->load($delid);
         $user->delete();
         }catch (\Exception $e){
            $this->messageManager->addErrorMessage($e->getMessage());
         }

        $this->messageManager->addSuccessMessage(__('Record Deleted   
        Successfully.!'));
        $this->_redirect('magecompcrud/user/user')
}

enter image description here

Thanks in advance:)

1
  • check class="page messages" exist in page or not. Commented Dec 20, 2019 at 8:56

1 Answer 1

0

Working with message manager

Messaging in Magento 2 is handled by a message manager object. So if you want to write messages, you need to get an instance of it. The prefered method is to inject this class into your class by adding this to your __construct method:

protected messageManager;

public function __construct(
    ... 
    \Magento\Framework\Message\ManagerInterface $messageManager,
    ...
){
    $this->messageManager = $messageManager;
    ...
}

With this, you can call one of the following messages: PHP

$this->messageManager->addError(__("Error"));
$this->messageManager->addWarning(__("Warning"));
$this->messageManager->addNotice(__("Notice"));
$this->messageManager->addSuccess(__("Success"));

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.