while trying to perform crud operation i came across
$this->coreRegistry->register(RegistryConstants::CURRENT_AUTHOR_ID, $authorId);
to perform edit action they got the id param and registered in core registry.
I'm new to this and looking for logic and concept behind this…
why do we need core registry in magento 2?
Best Answer
In Magento 1, it was possible to register a global variable with the static registry method.
Many extensions, include core Magento extensions, ended up using this from controller action methods to pass variables into the views.
While its future is uncertain (not marked explicitly supported via an @api, but not marked @deprecated) Magento 2 does have a similar registry object that should help easy the transition for extensions. The class is
Magento\Framework\Registry
, and you can inject it in any constructor.and then set variables with
and fetch those variables back (even from a different object –
Magento\Framework\Registry
is ashared/singleton
object)Source: magento-quickies.alanstorm