Home » Magento18 February 2010

Magento: How to set and get registry?

Registry means registering or creating a new variable which is to be used later on in the project/code. The registry variable acts as a global variable which can be used anywhere.

Here are the functions to register, unregister and fetch a registry variable.

register(): register a variable
unregister(): unregister a variable
registry(‘VARIABLE_NAME’): fetch registry variable value

We can store anything in the registry variable. It can be integer, string, array, etc.

The below example shows how to create, fetch and destroy registry variable.

The Store ID of the shop is stored in registry with variable name store_id. Mage::app()->getStore()->getId() gives the current store id.

Register variable

Fetch registry variable value

Destroy / Unregister the variable

Hope this helps. Thanks.

Magento

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Kat

    Hi Mukesh,
    thanks for this, really useful!

    One thing that keeps popping into my mind is, is this registry variable available only to one user or to all users that are currently on page (to several users).
    What I do is I set registry var for one user and later I empty it. I’m just wondering if in between some other user gets this var or even overwrite this var..

    Thanks for useful data throughout your blog!
    cheers

  • kiddo

    thanks for the tut . it helped

  • kiddo

    thanks for the tut . it helped

  • Pranay

     Hi Mukesh,

    Thanks for guiding  in very simple way…thats gr8.

  • AnyDog

    Hi,
    I stumbled to this post while searching solution to this – geting layout block top.links into WordPress and fetching locale/store view using WP (multilingual enabled) variable (if $wp_lang = en …etc).Can this code be applied to my piece of code to get top.links block in different store view (language) ?Here’s my code:$layout = Mage::app()->getLayout();$layout->getUpdate() ->addHandle(‘default’) ->load();$layout->generateXml()->generateBlocks();$topLinks = $layout->getBlock(‘top.links’)->toHtml();echo $topLinks;

    Thank you

  • Hassan Nisar Khan

    hi, im new to magneto..
    is it possible to register a value from admin section (admin controller) and fetch from the stranded ( fronted ) controller ,