Issues

ZF-6313: Zend Framework Quick Start : Registry - Use of Static or Object Instantiation

Description

The Quick Start uses the object instantiation method, which the Programmer's Reference Guide refers to as atypical and possibly buggy - http://framework.zend.com/manual/en/…. Furthermore, the example doesn't use the $registry = new Zend_Registry(array(), ArrayObject::ARRAY_AS_PROPS) but instead sets the Registry property directly with $registry->configuration = $configuration; For me this only added confusion as to which method was the "best practice" for setting the Registry Object properties. I suggest the Quick Start use the static methods mentioned as typical in the Programmer's Reference Guide and possibly refer to the Object Instantiation method as an option.

so instead of: $registry = Zend_Registry::getInstance(); $registry->configuration = $configuration; $registry->dbAdapter = $dbAdapter;

it would be something like: Zend_Registry::set('configuration', $configuration); Zend_Registry::set('dbAdapter', $dbAdapter);

Also, the Registry entries are not being used in the bootstrap example, they are only being set. Would it make more sense to apply them as well?

so, instead of: $dbAdapter = Zend_Db::factory($configuration->database); Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);

it would be something like: Zend_Registry::set('dbAdapter', Zend_Db::factory(Zend_Registry::get('config')->database)); Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('dbAdapter'));

or: $dbAdapter = Zend_Db::factory(Zend_Registry::get('config')->database); Zend_Registry::set('dbAdapter', $dbAdapter); Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('dbAdapter'));

Comments

{quote} so instead of:


$registry = Zend_Registry::getInstance();
$registry->configuration = $configuration;
$registry->dbAdapter = $dbAdapter;

it would be something like:


Zend_Registry::set('configuration', $configuration);
Zend_Registry::set('dbAdapter', $dbAdapter);

{quote} The problem refers to an old version of the documentation.

{quote} so, instead of:


$dbAdapter = Zend_Db::factory($configuration->database);
Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);

it would be something like:


Zend_Registry::set('dbAdapter', Zend_Db::factory(Zend_Registry::get('config')->database));
Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('dbAdapter'));

or:


$dbAdapter = Zend_Db::factory(Zend_Registry::get('config')->database);
Zend_Registry::set('dbAdapter', $dbAdapter);
Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('dbAdapter'));

{quote} Store the Db adapter in the registry is a very bad idea, because you do not need it.