Zend Framework Zend::updateRegister??
Moderator: General Moderators
- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
Zend Framework Zend::updateRegister??
As all Zend Framework programmers know the Zend::Register static function only allows you to register a object once. However, I need to update the object that was saved in the registry. How does one update a registered object?
- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
I think that was an intended design decision... I don't think your supposed to be able to resave anything into the registry...
Zend Framework Manual wrote:The $name argument must be a string, only objects may be stored in the registry, an object can never be removed from the registry, and an instance can only be stored once in the registry. Failure to obey these rules will result in Zend_Exception being thrown.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I don't see how that leads to needing to register the class again. Your navigation panel is added to the view, which is the instance returned from the framework's registry. If you pulled out the view correctly (as a reference) you'd be editing the one in the registry..
Do I need to keep repeating myself?
Do I need to keep repeating myself?
Here is an example for you to play around with...
Code: Select all
<?php
/**
* Test object to show you how objects are handled by reference
*/
class TestObject
{
public $foobar = null;
public function __construct($value = null)
{
$this->foobar = $value;
}
}
/**
* Test registry
*/
class SingleRegistry
{
protected $_value = null;
public function set($value)
{
if(is_null($this->_value))
{
if(is_object($value))
{
$this->_value = $value;
return;
}
throw new Exception('Value must be an object');
}
throw new Exception('You can only store one value in the registry, and you can not resave it. (no need to)');
}
public function get()
{
return $this->_value;
}
}
$Registry = new SingleRegistry; // Instantiate Registry
$Object = new TestObject('foobar'); // Instantiate our test object (to be registered)
try
{
$Registry->set($Object); // Set the object into the registry
?><pre><?php
print_r($Registry); // See how our test object looks in the registry (foobar should be set to 'foobar')
?></pre><?php
$ObjectAgain = $Registry->get(); // Retrieve our object from registry
$ObjectAgain->foobar = 'test'; // Change it's values
}
catch (Exception $e)
{
echo $e;
}
?><pre><?php
print_r($Registry); // Check how the test object looks again HEY WOW! It's changed! PHP5 ROCKS!!!
?></pre>- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
You don't need to... PHP5 does it for you (which is required for Zend Framework to work). Look here:
http://www.zend.com/php5/articles/engin ... hanges.php
http://www.zend.com/php5/articles/engin ... hanges.php
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I am not sure you are looking at this from the right perspective. I am not intending to insult you, I am merely recalling an experience I had recently with a registry object.
The registry is used as a sort of store that allows the checking in and checking out of objects, vars, etc. Once an item is registered it is not changeable (hence keeping its global property, if you will). When dealing with registering an object, all methods and properties of the object stay with that object (in PHP5). So if you instantiate an object, set some object properties, register the object, then call that object from elsewhere within the app and set more object properties, all set properties will be available to you in within that object.
Is this at all related to what you want to know?
The registry is used as a sort of store that allows the checking in and checking out of objects, vars, etc. Once an item is registered it is not changeable (hence keeping its global property, if you will). When dealing with registering an object, all methods and properties of the object stay with that object (in PHP5). So if you instantiate an object, set some object properties, register the object, then call that object from elsewhere within the app and set more object properties, all set properties will be available to you in within that object.
Is this at all related to what you want to know?