I see. I'll follow the approach which you recommended.
Thank you both Matthews!

On Thu, Jul 10, 2008 at 5:47 PM, Matthew Weier O'Phinney <[EMAIL PROTECTED]>
wrote:

> -- AmirBehzad Eslami <[EMAIL PROTECTED]> wrote
> (on Thursday, 10 July 2008, 04:54 PM +0330):
> > >> why don't you just store the config object in the registry, and
> > >> then pull values from there...?
> >
> > Actually I was using the approach you mentioned above,
> > until I realized that it requires more memory, since an entire
> > instance of Zend_Config is stored into Zend_Registry.
> > So I decided to store only config's _DATA_ into
> > Zend_Registry to save the mem.
>
> A Zend_Config should not take up enough memory that you need to be
> worried about it -- certainly it would be only slightly more than
> storing the data directly in the registry. This is smelling a bit of
> premature optimization.
>
> > By the way, I found a way to store config's key-value pairs at once
> > into Zend_Registry (thanks to the Zend_Registy for extending
> > ArrayObject).
> >
> > Zend_Registry::setInstance(
> >     new Zend_Registry($config->toArray()));
> > unset($config);
>
> The problem with the above approach is if you've set any registry items
> previously -- though my guess is this would be unlikely.
>
> > > This is a much better solution [storing the config object in the
> registry],
> > > as then you don't need to worry about checking to see if various
> > > registry keys are set.
> > I don't see how. Even I have a config object, I can't be 100%-certain
> about
> > existence of its key/value pairs. Perhaps the config file lacks a key.
> > Would you please explain a little more. Maybe I'm missing something.
>
> If the key does not exist in the config object, then it simply returns a
> null. With the registry, if the key does not exist, get() will throw an
> exception -- which is why you typically need to check with
> isRegistered() prior to pulling values from the Registry.
>
>
> > On Thu, Jul 10, 2008 at 4:20 PM, Matthew Weier O'Phinney <
> [EMAIL PROTECTED]>
> > wrote:
> >
> >     -- AmirBehzad Eslami <[EMAIL PROTECTED]> wrote
> >     (on Thursday, 10 July 2008, 02:03 PM +0330):
> >     > Hi list,
> >     > I'm trying to store values from a Zend_Config object into
> Zend_Registry.
> >     >
> >     > $config = new Zend_Config_Xml(APP_DIR . '/config.xml', $curr_env);
> >     > foreach ($config as $key => $value) {
> >     >     Zend_Registry::set($key, $value);
> >     > }
> >     >
> >     > As you see, I'm iterating over $config object to store the values
> into
> >     the
> >     > registry.
> >     > Is there any plan to implement a special method (perhaps
> setFromArray())
> >     to
> >     > facilitate this action? Is there any other way to store multiple
> values
> >     into
> >     > the
> >     > registry at once, with a single line of code?
> >
> >     Umm... why don't you just store the config object in the registry,
> and
> >     then pull values from there...?
> >
> >        // setting...
> >        Zend_Registry::set('config', $config);
> >
> >        // retrieving...
> >        $env = Zend_Registry::get('config')->env;
> >
> >     This is a much better solution, as then you don't need to worry about
> >     checking to see if various registry keys are set.
> >
> >     --
> >     Matthew Weier O'Phinney
> >     Software Architect       | [EMAIL PROTECTED]
> >     Zend Framework           | http://framework.zend.com/
> >
> >
> >
> >
> > --
> > Kind regards,
> > -behzad
>
> --
> Matthew Weier O'Phinney
> Software Architect       | [EMAIL PROTECTED]
> Zend Framework           | http://framework.zend.com/
>



-- 
Kind regards,
-behzad

Reply via email to