WHAT'S HOT
Prev | Current Page 376 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

A Singleton will not allow this, but using a Registry will give
you the benefits of the easily accessible object without the drawbacks. This problem is so common that the
Zend Framework provides the Zend_Registry class that implements the Registry pattern. For simple access,
there are three main functions that form the basic API of Zend_Registry and usage is shown in listings 17.15
and 17.16.
Listing 17.15 Storing an object to the Zend_Registry
// bookstrap class
$config = $this->loadConfig();
Zend_Registry::set('config', $config); A A Static function for easy usage
Listing 17.16 Retrieving an object from the Zend_Registry
// bookstrap class
$config = Zend_Registry::get('config'); A A Retrieve via key name: 'config'
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 60
The only complication to be aware of with Zend_Registry is that you must ensure that you a unique key
when you store the object into the registry, otherwise you will overwrite the previously stored object of the
same name. Other than that, as Zend_Registry provides a pair of static functions that makes using a registry
easier than modifying a class to make it a Singleton. The key components of the implementation are shown in
listing 17.


Pages:
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
Adamski Danny gry kasynowe Paula Abdul Athlete