Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-13-2007, 10:58 PM
Junior Member
 
Join Date: Jul 2007
Posts: 7
Default Problem with Zend_Registry and ArrayObject::ARRAY_AS_PROPS parameter

Hi,

I can't get the Zend_Registry to work as an object instead of an array.

I use the following code in the bootstrap file:

PHP Code:
# Load everything from config.ini.
$config = new Zend_Config_Ini('config.ini'null);

# Create a new Zend_Registry from the config.
$registry = new Zend_Registry($config->toArray(), ArrayObject::ARRAY_AS_PROPS);

# Unset the static instance.
Zend_Registry::_unsetInstance();

# Set the static instance.
Zend_Registry::setInstance($registry);

# Test.
$registry Zend_Registry::getInstance();
echo 
$registry->system->name;
echo 
'<br />';
echo 
$registry->system->time->zone
The content of config.ini is:

PHP Code:
[system]
name            "Zend_Registry Test"
time.zone       "Europe/Brussels"

[database]
username        "root"
password        "abc123!"
name            "zend"
hostname        "localhost"
type            "PDO_MYSQL" 
I already checked the Zend Framework documentation. They warn you for using the ArrayObject::ARRAY_AS_PROPS parameter:

Quote:
Originally Posted by Zend Framework Documentation
25.1.5. Accessing the Registry as an Object

You may also find it convenient to access the registry in an object-oriented fashion, using index names as object properties. To do this, you need to specifically construct the registry object using the ArrayObject::ARRAY_AS_PROPS option, and initialize the static instance. You must do this before the static registry has been accessed for the first time. Beware of using this option, since some versions of PHP have bugs when using the registry with this option.
But I'm using the latest version of PHP (5.2.3), so that can't be the problem I guess? Can someone help me out here?

Thanks in advance for any response.

Kind regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-14-2007, 09:52 AM
Member
 
Join Date: Aug 2007
Location: Tarnow/Krakow, Poland, EU
Posts: 30
Default

It sucks, but you can only use 1-dimensional array:

Code:
echo $registry->system['name']; 
echo '<br />'; 
echo $registry->system['time']['zone'];
Update:
You can also do this:

Code:
# Load everything from config.ini.
$config = new Zend_Config_Ini('config.ini', null); 

# Create a new Zend_Registry not from, but with the config. 
$registry = new Zend_Registry(array('config' => $config), ArrayObject::ARRAY_AS_PROPS);

# Unset the static instance. 
Zend_Registry::_unsetInstance(); 

# Set the static instance. 
Zend_Registry::setInstance($registry); 

# Test. 
$registry = Zend_Registry::getInstance(); 
echo $registry->config->system->name;
echo '<br />'; 
echo $registry->config->system->time->zone;
__________________
I don't trust anything that bleeds for five days and doesn't die.
www.inetive.pl

Last edited by borec : 08-14-2007 at 09:55 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-15-2007, 03:06 AM
Junior Member
 
Join Date: Jul 2007
Posts: 7
Default

Okay, thanks. I think I'll use your second suggestion.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:04 PM.