Re: [fw-general] Zend_Config_Ini - keys as an array

2008-04-16 Thread Rob Allen


On 15 Apr 2008, at 18:13, Matthew Weier O'Phinney wrote:

-- Vincent <[EMAIL PROTECTED]> wrote
(on Tuesday, 15 April 2008, 06:22 PM +0200):

On 4/15/08, Paul Simon <[EMAIL PROTECTED]> wrote:

   Hi,

   I've been using Zend_Config_Ini successfully in a number of  
applications.
   I'm wondering if the following is the correct way to configure  
arrays? My
   concern is that I don't see it documented anywhere to add  
brackets to the
   end of keys, like plugin[]. I just happened on a comment at  
[http://
   us.php.net/manual/en/function.parse-ini-file.php#75983] saying  
it can be
   done. Does anybody else use 'key[]' to configure arrays? Thanks,  
Paul


   Set config.php
   ---
   [Production]
   ; plugins
   plugin[] = Init
   plugin[] = Authenticate
   plugin[] = Access
   plugin[] = Wrapper

   Get array
   ---
   $conf = new Zend_Config_Ini('config.php','Production');
   $plugins = $conf->plugin->toArray();

   Dump $plugins
   ---
   array (
 0 => 'Init',
 1 => 'Authenticate',
 2 => 'Access',
 3 => 'Wrapper',
   )




I think you're supposed to do it like this:

Set config.php
---
[Production]
; plugins
plugin.0 = Init
plugin.1 = Authenticate
plugin.2 = Access
plugin.3 = Wrapper


No, you can't do this...



Yes you can do this :)

either

$plugins = $config->plugins->toArray();

or

$plugin1 = $config->plugins->{1};  // The braces are important!


will work.

I didn't know about using [], but that's a nice solution too.

Regards,

Rob...



RE: [fw-general] Zend_Config_Ini - keys as an array

2008-04-15 Thread Robert Castley
Excellent find!  Thank you!  You have managed to solve an age old problem
for me :-)

- Robert 

-Original Message-
From: Paul Simon [mailto:[EMAIL PROTECTED] 
Sent: 15 April 2008 17:03
To: fw-general@lists.zend.com
Subject: [fw-general] Zend_Config_Ini - keys as an array

Hi,

I've been using Zend_Config_Ini successfully in a number of applications.
I'm wondering if the following is the correct way to configure arrays? My
concern is that I don't see it documented anywhere to add brackets to the
end of keys, like plugin[]. I just happened on a comment at
[http://us.php.net/manual/en/function.parse-ini-file.php#75983] saying it
can be done. Does anybody else use 'key[]' to configure arrays? Thanks, Paul

Set config.php
---
[Production]
; plugins
plugin[] = Init
plugin[] = Authenticate
plugin[] = Access
plugin[] = Wrapper

Get array
---
$conf = new Zend_Config_Ini('config.php','Production');
$plugins = $conf->plugin->toArray();

Dump $plugins
---
array (
  0 => 'Init',
  1 => 'Authenticate',
  2 => 'Access',
  3 => 'Wrapper',
)







This email has been scanned for all known viruses by the MessageLabs Email
Security Service and the Macro 4 plc internal virus protection system.




This email has been scanned for all known viruses by the MessageLabs Email 
Security Service and the Macro 4 plc internal virus protection system.


Re: [fw-general] Zend_Config_Ini - keys as an array

2008-04-15 Thread Vincent
On 4/15/08, Matthew Weier O'Phinney <[EMAIL PROTECTED]> wrote:
>
> -- Vincent <[EMAIL PROTECTED]> wrote
> (on Tuesday, 15 April 2008, 06:22 PM +0200):
>
> > On 4/15/08, Paul Simon <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > I've been using Zend_Config_Ini successfully in a number of
> applications.
> > I'm wondering if the following is the correct way to configure
> arrays? My
> > concern is that I don't see it documented anywhere to add brackets
> to the
> > end of keys, like plugin[]. I just happened on a comment at [http://
> > us.php.net/manual/en/function.parse-ini-file.php#75983] saying it
> can be
> > done. Does anybody else use 'key[]' to configure arrays? Thanks,
> Paul
> >
> > Set config.php
> > ---
> > [Production]
> > ; plugins
> > plugin[] = Init
> > plugin[] = Authenticate
> > plugin[] = Access
> > plugin[] = Wrapper
> >
> > Get array
> > ---
> > $conf = new Zend_Config_Ini('config.php','Production');
> > $plugins = $conf->plugin->toArray();
> >
> > Dump $plugins
> > ---
> > array (
> >   0 => 'Init',
> >   1 => 'Authenticate',
> >   2 => 'Access',
> >   3 => 'Wrapper',
> > )
> >
> >
> >
> >
> > I think you're supposed to do it like this:
> >
> > Set config.php
> > ---
> > [Production]
> > ; plugins
> > plugin.0 = Init
> > plugin.1 = Authenticate
> > plugin.2 = Access
> > plugin.3 = Wrapper
>
>
> No, you can't do this...
>
>
> > Get array
> > ---
> > $conf = new Zend_Config_Ini('config.php',
> > 'Production');
> > // Now you can access them like:
> > echo $conf->plugin->0; // Displays 'Init'
>
>
> ... because the above is invalid PHP. (Try it; you'll get an "unexpected
> T_LNUMBER" parse error.)


Ah, of course, stupid. I knew I was missing something, thanks for
correcting...

-- 
Vincent


Re: [fw-general] Zend_Config_Ini - keys as an array

2008-04-15 Thread Matthew Weier O'Phinney
-- Vincent <[EMAIL PROTECTED]> wrote
(on Tuesday, 15 April 2008, 06:22 PM +0200):
> On 4/15/08, Paul Simon <[EMAIL PROTECTED]> wrote:
> 
> Hi,
> 
> I've been using Zend_Config_Ini successfully in a number of applications.
> I'm wondering if the following is the correct way to configure arrays? My
> concern is that I don't see it documented anywhere to add brackets to the
> end of keys, like plugin[]. I just happened on a comment at [http://
> us.php.net/manual/en/function.parse-ini-file.php#75983] saying it can be
> done. Does anybody else use 'key[]' to configure arrays? Thanks, Paul
> 
> Set config.php
> ---
> [Production]
> ; plugins
> plugin[] = Init
> plugin[] = Authenticate
> plugin[] = Access
> plugin[] = Wrapper
> 
> Get array
> ---
> $conf = new Zend_Config_Ini('config.php','Production');
> $plugins = $conf->plugin->toArray();
> 
> Dump $plugins
> ---
> array (
>   0 => 'Init',
>   1 => 'Authenticate',
>   2 => 'Access',
>   3 => 'Wrapper',
> )
> 
> 
> 
> 
> I think you're supposed to do it like this:
> 
> Set config.php
> ---
> [Production]
> ; plugins
> plugin.0 = Init
> plugin.1 = Authenticate
> plugin.2 = Access
> plugin.3 = Wrapper

No, you can't do this...

> Get array
> ---
> $conf = new Zend_Config_Ini('config.php',
> 'Production');
> // Now you can access them like:
> echo $conf->plugin->0; // Displays 'Init'

... because the above is invalid PHP. (Try it; you'll get an "unexpected
T_LNUMBER" parse error.)

I hadn't tried what the original poster suggested before, but I've
verified it works... and I'll be using it in the future.

BTW, the equivelent XML would be:




Init
Authenticate
Access
Wrapper




> // Or you could convert it to an array which would return the array described
> $plugins = $conf->plugin->toArray();
> 
> Dump $plugins
> ---
> array (
>  0 => 'Init',
>  1 => 'Authenticate',
>  2 => 'Access',
>  3 => 'Wrapper',
> )

-- 
Matthew Weier O'Phinney
Software Architect   | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/


Re: [fw-general] Zend_Config_Ini - keys as an array

2008-04-15 Thread Vincent
On 4/15/08, Paul Simon <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I've been using Zend_Config_Ini successfully in a number of applications.
> I'm wondering if the following is the correct way to configure arrays? My
> concern is that I don't see it documented anywhere to add brackets to the
> end of keys, like plugin[]. I just happened on a comment at [
> http://us.php.net/manual/en/function.parse-ini-file.php#75983] saying it
> can be done. Does anybody else use 'key[]' to configure arrays? Thanks, Paul
>
> Set config.php
> ---
> [Production]
> ; plugins
> plugin[] = Init
> plugin[] = Authenticate
> plugin[] = Access
> plugin[] = Wrapper
>
> Get array
> ---
> $conf = new Zend_Config_Ini('config.php','Production');
> $plugins = $conf->plugin->toArray();
>
> Dump $plugins
> ---
> array (
>   0 => 'Init',
>   1 => 'Authenticate',
>   2 => 'Access',
>   3 => 'Wrapper',
> )
>
>
>
I think you're supposed to do it like this:

Set config.php
---
[Production]
; plugins
plugin.0 = Init
plugin.1 = Authenticate
plugin.2 = Access
plugin.3 = Wrapper

Get array
---
$conf = new Zend_Config_Ini('config.php','Production');
// Now you can access them like:
echo $conf->plugin->0; // Displays 'Init'
// Or you could convert it to an array which would return the array
described
$plugins = $conf->plugin->toArray();

Dump $plugins
---
array (
 0 => 'Init',
 1 => 'Authenticate',
 2 => 'Access',
 3 => 'Wrapper',
)


-- 
Vincent