1

I know how to register, how to get the value from registry and how to unregister.

for register

$this->_coreRegistry->register('customer_save_observer_executed_' . $customer_Data->getId(),true); 

for get the value from register

$this->_coreRegistry->registry('customer_save_observer_executed_' . $customer_Data->getId()) 

for unregister

$this->_coreRegistry->unregister('customer_save_observer_executed_' . $customer_Data->getId()); 

Now I don't know how long register will hold this information untill if I unregister.

Expecting valuable suggestions/help?

1 Answer 1

4

If you go to Magento\Framework\Registry you can see a __destruct method specified there.

Register basically stores your data inside an array type object using key value pair.

As soon as you stop using that class it will automatically calls the __destruct method and that will unregister that variable.

Check this link to understand how it works.

And this is when destructor wont be called.

EDIT

Lets suppose you are using the registry class inside a controller. You can access the registry throughout the controller because you have instantiated that registry class in your constructor. But as soon as your execution goes to diff controller you cant access that registry variable. Because that would be destroyed by __destruct() automatically. You dont have to unregister it.

4
  • So __destruct method won't be call until we call unregister method? Commented Jun 20, 2017 at 7:09
  • Not really. __destruct gets called automatically. unregister remove a variable by its key and that has to be called. Commented Jun 20, 2017 at 7:19
  • Actually First time user I created as a customer well. After logged into dashboard I am trying to update address from admin panel it's throwing error Registry key customer_save_observer_executed_9 already exist. So how can I do in this situation? If I want to save Commented Jun 20, 2017 at 7:29
  • Somehow the value is still exists in registry. Probably your execution stopped abruptly or calling exit inside your constructor or something else. Have you tried clearing cache? Is it happening for each customers? Commented Jun 20, 2017 at 7:40

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.