the_woodsman is right - if you can cope with Cake's array structure
then your app will be more consistent, however there are times when
you do need the data in a certain format, and plain php can cope with
this easily. I'm not sure how the Set class can do this easily and as
quick as the following.
$users2 = array();
foreach ($users as $user) {
$users2[] = array(
'id' => $user['Users']['id'],
'name' => $user['Users']['name'],
'total_cost' => $user[0]['total_cost'],
'descr' => $user['group']['descr']
);
}
$users = $users2;
// or for php5
foreach ($users as &$user) {
$user = array(
'id' => $user['Users']['id'],
'name' => $user['Users']['name'],
'total_cost' => $user[0]['total_cost'],
'descr' => $user['group']['descr']
);
}
On Apr 11, 8:56 pm, the_woodsman <[EMAIL PROTECTED]> wrote:
> I believe Cake's Set class is used for manipulating arrays in fairly
> complex ways, and might be useful in this situation-
>
> http://www.thinkingphp.org/2007/02/24/cake-12s-set-class-eats-arrays-...
>
> However, make sure you really *need* the data in this format, rather
> than are just doing it out of force of habit - you get a lot more out
> of Cake if you go with its conventions rather than against them!
>
> On Apr 11, 11:38 am, trav <[EMAIL PROTECTED]> wrote:
>
> > hi bakers!
>
> > Im not sure if this is a cake question or more just a general php
> > question.
>
> > When i create a database view that includes some calculations and i
> > perform a findAll against that view cake give the following output:
>
> > Array
> > (
> > [0] => Array
> > (
> > [Users] => Array
> > (
> > [id] => 1
> > [name] => 'jane'
> > )
>
> > [0] => Array
> > (
> > [total_cost] => 400
> > )
> > [group] => Array
> > (
> > [descr] => 'public'
> > )
> > )
>
> > I really need the following output:
>
> > Array (
> > [id] => 1
> > [name] => 'jane'
> > [total_cost] => 400
> > [descr] => 'public'
> > )
>
> > Can cake help me out here or am i left to code a solution in php?
>
> > Cheers,
> > Trav.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---