Magento 2 - On save user insert to other table on database
-
28-02-2021 - |
题
I created a new tab on User edit, with a form
I want to save the data getting from the form the other table on Database (Ex: test_table
) when I click on save user
button, is there any method to do that?
I try to use events
XML:
<event name="customer_account_edited">
<observer name="test_event" instance="Testing\Test\Observer\TestUserOnSave"/>
</event>
PHP (TestUserOnSave)
public function execute(Observer $observer){
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logger.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('test events');
}
But it's doesn't work, is there any solution?
解决方案
You need to create module with observer that will load for example on
' admin_user_save_after` event
In observer you can insert Your function.
List of events: https://www.mageplaza.com/magento-2-module-development/magento-2-events.html