Issues

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

Issue Type: Docs: Improvement Created: 2009-04-16T00:08:13.000+0000 Last Updated: 2013-03-09T03:52:10.000+0000 Status: Closed Fix version(s): Reporter: Dan Entous (dan_nl) Assignee: Frank Brückner (frosch) Tags: - Zend_Registry

Related issues: Attachments:

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

Posted by Frank Brückner (frosch) on 2013-03-09T03:51:35.000+0000

{quote} so instead of:

<pre class="highlight">
$registry = Zend_Registry::getInstance();
$registry->configuration = $configuration;
$registry->dbAdapter = $dbAdapter;

it would be something like:

<pre class="highlight">
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:

<pre class="highlight">
$dbAdapter = Zend_Db::factory($configuration->database);
Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);

it would be something like:

<pre class="highlight">
Zend_Registry::set('dbAdapter', Zend_Db::factory(Zend_Registry::get('config')->database));
Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('dbAdapter'));

or:

<pre class="highlight">
$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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts