I am trying to create afterSave plugin for my admin form save action controller of my custom module. The purpose of this is to save some data into second table once all data completely save in first table.

Here is my di.xml file code :

<type name="Namespace\Module\Controller\Adminhtml\Options\Save">
    <plugin name="save_option_label" type="Namespace\Module\Plugin\OptionlabelSave" sortOrder="1" />

I have also created OptionlabelSave.php file inside \Plugin\ directory.

Here is the code :


namespace Namespace\Module\Plugin;

 * Class OptionlabelSave
 * @package Namespace\Module\Plugin
class OptionlabelSave
    public function afterSave(Namespace\Module\Controller\Adminhtml\Options\Save $subject, $result) {
        echo 'test save'; exit;

        return $result;

However, when I click on save button in admin edit form I am not getting 'test save' printed on my screen. Am I missing anything here?

Please help. That would be highly appreciated.


  • Can you please add Namespace\Module\Controller\Adminhtml\Options\Save code here? Aug 28, 2018 at 7:56
  • Hello @RutveeSojitra. That is normal save data code using model nothing exceptional. I think I came to know from some googling that we can't use plugin actions after,around and before for Controller. It can be use for model. For controller we need to use Preference that is actually overwrite. Is it true? Aug 28, 2018 at 9:40
  • 1
    No, we can do also in controller please refer for more mageplaza.com/… Aug 28, 2018 at 9:52
  • @RutveeSojitra Thanks for the reference. I will refer it. Aug 28, 2018 at 10:07

1 Answer 1


I have found the solution myself. Earlier, I have used afterSave() method inside plugin file. Instead, we need to use either afterExecute() or aroundExecute() depending upon the type of requirement.

That's it!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.