On Thu, Feb 12, 2009 at 1:09 AM, mscdex <msc...@gmail.com> wrote:
>
> On Feb 11, 11:58 pm, Andre <andre_susan...@yahoo.com> wrote:
>> Hi all,
>> Can anyone help on writing the snippet using cakephp core utility
>> library to combine array?
>
> If you look at Set::combine (http://book.cakephp.org/view/662/
> combine), you'll notice that both the path for the key and/or the path
> for the value can be specially formatted instead of just specifying a
> normal path for each. There are many examples on that link that show
> the many different possibilities for generating the combined array.
>
> Here is an example snippet ($array contains the array you specified):
>        $service_name = $array[0]['Service']['name'];
>        $new_array = Set::combine($array, "0.Member.{n}.id", array("{1}, {0}-
> $service_name", "0.Member.{n}.first_name", "0.Member.{n}.last_name"));

Neato. I think I'm begining to understand combine().

You'd need to loop through the results, though, to deal with
$array[{n}] results. Would this work:

function afterFind($results, $primary = false)
{
        if ($primary)
        {
                foreach($results as $k => &$v)
                {
                        $v = Set::combine(
                                $v,
                                'Member.{n}.id',
                                array(
                                        '{1}, {0}-Service.name',
                                        'Member.{n}.first_name',
                                        'Member.{n}.last_name'
                                )
                        );
                }
                $v = Set::merge($v);
        }
        return $results;
}

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

Reply via email to