View Single Post
  #15 (permalink)  
Old 12-28-2007, 06:04 PM
blurphp blurphp is offline
Junior Member
 
Join Date: Dec 2007
Posts: 11
Send a message via MSN to blurphp Send a message via Yahoo to blurphp
Default

I am new to zend Framework ut I have noticed something that pertains to this thread.

When you load a config file into the regisrty in the bootstrapper
Code:
$config = new Zend_Config_Ini('application/config/Config.ini', 'general');
Zend_Registry::set('config', array($config));
get this when you dump the registry from the bootstrapper
Code:
$regisrty = Zend_Registry::get('config');
print_r($regisrty);
You get this:
Code:
Zend_Config_Ini Object
(
    [_nestSeparator:protected] => .
    [_allowModifications:protected] => 
    [_index:protected] => 0
    [_count:protected] => 1
    [_data:protected] => Array
        (
            [db] => Zend_Config Object
                (
                    [_allowModifications:protected] => 
                    [_index:protected] => 0
                    [_count:protected] => 2
                    [_data:protected] => Array
                        (
                            [adapter] => Mysqli
                            [params] => Zend_Config Object
                                (
                                    [_allowModifications:protected] => 
                                    [_index:protected] => 0
                                    [_count:protected] => 4
                                    [_data:protected] => Array
                                        (
                                            [dbname] => test
                                            [host] => localhost
                                            [username] => test
                                            [password] => test
                                        )

                                    [_loadedSection:protected] => 
                                    [_extends:protected] => Array
                                        (
                                        )

                                )

                        )

                    [_loadedSection:protected] => 
                    [_extends:protected] => Array
                        (
                        )

                )

        )

    [_loadedSection:protected] => general
    [_extends:protected] => Array
        (
        )

)
Now when you go to the Controller and dump the registry you get the same thing

Now if you try and access that area
Code:
$registry2 = $regisrty['Zend_Config_Ini Object']['db']['adapter'];
        print_r($registry2);
you get
Code:
Fatal error: Cannot use object of type Zend_Config_Ini as array in 
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Project\application\controllers\UserController.php on line 26
So I think it is setting the whole config file as the value instead of each var.

So I am loading the regisrty manually
Code:
$config = new Zend_Config_Ini('application/config/Config.ini', 'general');
$dbadapter = $config->db->adaptor;
Zend_Registry::set('dbadapter', $dbadapter);
It works. But having the whole file load would be better.

I could be wrong as I am still new to php and zf. Any suggestions on what is happening or how to fix would be appreciated.

Last edited by blurphp : 12-28-2007 at 06:19 PM.
Reply With Quote