The Magento registry is a globally accessible store of data that is used by all aspects of the Magento system. Recently a user asked me how to see the contents of the registry. After a little play I found a way to do this, however, be warned: to accomplish this you need to temporarily modify a core Magento file (Mage.php). Read on for more information
Mage.php and the Mage class
The main file of Magento is a file called Mage.php and is stored inside the app folder. This class contains a lot of useful functions which you will probably notice. Most of these functions are static which means they can be called without instantiating the class. This is great for global data access as it allows you to access data stores and useful functions from anywhere in Magento.
Open up Mage.php and have a look through. You should notice the private variable called $_registry. This contains an array which stores all of the registry information. To be able to access this array directly, add the following line inside the Mage class.
1
|
public static function getRegistry() { return self:: $_registry ; } |
This function will allow you to return the whole registry array as opposed to individual values. Using the following code, you will now have access to the registry array.
1
|
<?php $registryArray = Mage::getRegistry() ?> |
Now that you have the array, you can go ahead and manipulate it like you would any other array, however, I wouldn’t recommend this. This array contains many large objects, which themselves contain large objects inside of them. If you tried to run the print_r() command on this array, it would probably eat up your systems memory and cause your browser to crash.
Viewing the contents of the Magento registry
Rather than running print_r() on the whole array, let’s just look at the key’s, their data types and values/class names.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?php $registry = Mage::getRegistry() ?> <?php if ( count ( $registry ) > 0): ?> <h1>Registry Inspection: by Fishpig</h1> <ul> <?php foreach ( $registry as $index => $value ): ?> <li> Registry[ '<a href="#"><?php echo $index ?></a>' ] = (<em><?php echo gettype ( $value ) ?></em>) <strong> <?php if ( is_object ( $value )): ?> <?php echo get_class( $value ) ?> <?php elseif ( is_array ( $value )): ?> Array <?php else : ?> <?php echo $value ?> <?php endif ; ?> </strong> </li> <?php endforeach ; ?> </ul> <?php endif ; ?> <?php exit ?> |
Run the above code and you should get a print out similar to the following:
Undo the Mage.php changes!
Now that you have seen the contents of the registry, make sure you remove the function that you added to Mage.php!
- Registry['original_include_path'] = (string) .:/Applications/MAMP/bin/php5/lib/php
- Registry['_singleton/core/resource'] = (object) Mage_Core_Model_Resource
- Registry['_resource_singleton/core/resource'] = (object) Mage_Core_Model_Mysql4_Resource
- Registry['_resource_singleton/core/website'] = (object) Mage_Core_Model_Mysql4_Website
- Registry['_resource_singleton/core/store_group'] = (object) Mage_Core_Model_Mysql4_Store_Group
- Registry['_resource_singleton/core/store'] = (object) Mage_Core_Model_Mysql4_Store
- Registry['_singleton/core/cookie'] = (object) Mage_Core_Model_Cookie
- Registry['controller'] = (object) Mage_Core_Controller_Varien_Front
- Registry['_singleton/Mage_Cms_Controller_Router'] = (object) Mage_Cms_Controller_Router
- Registry['_singleton/Fishpig_WordPress_Custom_DatabaseConnection'] = (object) Fishpig_WordPress_Custom_DatabaseConnection
- Registry['_helper/wordpress/db'] = (object) Fishpig_WordPress_Helper_Db
- Registry['_helper/wordpress/data'] = (object) Fishpig_WordPress_Helper_Data
- Registry['_helper/core/data'] = (object) Mage_Core_Helper_Data
- Registry['_singleton/Fishpig_WordPress_Controller_Router'] = (object) Fishpig_WordPress_Controller_Router
- Registry['_resource_singleton/core/url_rewrite'] = (object) Mage_Core_Model_Mysql4_Url_Rewrite
- Registry['_singleton/core/layout'] = (object) Mage_Core_Model_Layout
- Registry['_helper/core/http'] = (object) Mage_Core_Helper_Http
- Registry['_singleton/core/session'] = (object) Mage_Core_Model_Session
- Registry['_singleton/core/design_package'] = (object) Mage_Core_Model_Design_Package
- Registry['_singleton/core/design'] = (object) Mage_Core_Model_Design
- Registry['_resource_singleton/core/design'] = (object) Mage_Core_Model_Mysql4_Design
- Registry['_singleton/core/translate'] = (object) Mage_Core_Model_Translate
- Registry['_singleton/core/locale'] = (object) Mage_Core_Model_Locale
- Registry['_singleton/core/translate_inline'] = (object) Mage_Core_Model_Translate_Inline
- Registry['_resource_singleton/core/translate'] = (object) Mage_Core_Model_Mysql4_Translate
- Registry['_helper/core/string'] = (object) Mage_Core_Helper_String
- Registry['_singleton/log/visitor'] = (object) Mage_Log_Model_Visitor
- Registry['_resource_singleton/log/visitor'] = (object) Mage_Log_Model_Mysql4_Visitor
- Registry['_helper/cms/page'] = (object) Mage_Cms_Helper_Page
- Registry['_singleton/cms/page'] = (object) Mage_Cms_Model_Page
- Registry['_resource_singleton/cms/page'] = (object) Mage_Cms_Model_Mysql4_Page
- Registry['_singleton/googleoptimizer/observer'] = (object) Mage_GoogleOptimizer_Model_Observer
- Registry['_helper/googleoptimizer/data'] = (object) Mage_GoogleOptimizer_Helper_Data
- Registry['_helper/page/layout'] = (object) Mage_Page_Helper_Layout
- Registry['_singleton/page/config'] = (object) Mage_Page_Model_Config
- Registry['_helper/page/data'] = (object) Mage_Page_Helper_Data
- Registry['_singleton/customer/observer'] = (object) Mage_Customer_Model_Observer
- Registry['_singleton/customer/config_share'] = (object) Mage_Customer_Model_Config_Share
- Registry['_singleton/customer/session'] = (object) Mage_Customer_Model_Session
- Registry['_helper/customer/data'] = (object) Mage_Customer_Helper_Data
- Registry['_helper/catalog/data'] = (object) Mage_Catalog_Helper_Data
- Registry['_helper/catalog/map'] = (object) Mage_Catalog_Helper_Map
- Registry['_helper/catalogsearch/data'] = (object) Mage_CatalogSearch_Helper_Data
- Registry['_helper/checkout/cart'] = (object) Mage_Checkout_Helper_Cart
- Registry['_singleton/checkout/cart'] = (object) Mage_Checkout_Model_Cart
- Registry['_singleton/checkout/session'] = (object) Mage_Checkout_Model_Session
- Registry['_helper/checkout/data'] = (object) Mage_Checkout_Helper_Data
- Registry['_resource_singleton/poll/poll'] = (object) Mage_Poll_Model_Mysql4_Poll
- Registry['_resource_singleton/poll/poll_answer'] = (object) Mage_Poll_Model_Mysql4_Poll_Answer
- Registry['_helper/wishlist/data'] = (object) Mage_Wishlist_Helper_Data
- Registry['_helper/contacts/data'] = (object) Mage_Contacts_Helper_Data
- Registry['_singleton/catalog/session'] = (object) Mage_Catalog_Model_Session
from:http://fishpig.co.uk/viewing-the-registry-contents-in-magento/