Zend registry

From EKiniWiki

Jump to: navigation, search

Quoted from: http://framework.zend.com/wiki/display/ZFDOCDEV/25.+Zend_Registry

The registry is a container for storing objects and values in the application space. By storing the value in the registry, the same object is always available throughout your application. This mechanism is an alternative to using global storage.

[edit] Setting Values

I did this in my bootstrap file (index.php) to globally set the upload directory for my script.

Zend_Registry::set('uploadDir', '/home/webmaster/public_html/ssms/uploads'); 

[edit] Getting Values

Then in my controllers/views, I could get the values set by doing this:

<?=Zend_Registry::get('uploadDir'); ?>


[edit] Check If Registry Exists

This is how to check if a certain element in the registry is set.

if (Zend_Registry::isRegistered('album_meta')) {
    echo 'Albums: ';
    echo ucwords(Zend_Registry::get('album_meta'));
}
Personal tools
Bookmarks