I would use Model::find('list'), and let cakephp do its magic

On 30 mar, 11:20, cricket <[email protected]> wrote:
> I have an array of country data that I'm trying to adjust so it's
> suitable to pass to FormHelper for select options with optgroup
> labels. Set::combine has gotten me almost there but not quite.
>
> Here's the data:
>
> Array
> (
>     [0] => Array
>         (
>             [id] => 1
>             [iso_code] => US
>             [name] => United States
>             [regions] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 4
>                             [country_id] => 1
>                             [iso_code] => AZ
>                             [name] => Arizona
>                         )
>
>                     [1] => Array
>                         (
>                             [id] => 7
>                             [country_id] => 1
>                             [iso_code] => CA
>                             [name] => California
>                         )
>                         ...
>                     [30] => Array
>                         (
>                             [id] => 63
>                             [country_id] => 1
>                             [iso_code] => WI
>                             [name] => Wisconsin
>                         )
>
>                 )
>
>         )
>
>     [1] => Array
>         (
>             [id] => 2
>             [iso_code] => CA
>             [name] => Canada
>             [regions] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 6
>                             [country_id] => 2
>                             [iso_code] => BC
>                             [name] => British Columbia
>                         )
>                         ...
>
> I tried:
>
> $options = Set::combine(
>         $data,
>     '{n}.name',
>         '{n}.regions.{n}.name'
> );
>
> This creates:
>
> Array
> (
>     [United States] => Array
>         (
>             [0] => Arizona
>             [1] => California
>             [2] => Colorado
>                         ...
>         )
>
>     [Canada] => Array
>         (
>             [0] => British Columbia
>                         ...
>
> What I require:
>
> Array
> (
>     [United States] => Array
>         (
>             [AZ] => Arizona
>             [CA] => California
>             [CO] => Colorado
>                         ...
>         )
>
>     [Canada] => Array
>         (
>             [BC] => British Columbia
>                         ...
>
> Can anyone think of a way to do that with Set?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to