Thursday, October 1, 2009

Re: Question about on merge two different Model paginate

On Thu, Oct 1, 2009 at 9:08 AM, byqsri <marco.rizzetto@gmail.com> wrote:
>
> Can someone help me about this?
>
> On 7 Set, 09:13, "marco.rizze...@gmail.com" <marco.rizze...@gmail.com>
> wrote:
>> Hi
>> I have this situation:
>> I have a model Event and a model News ,  Both models have  the field
>> 'created' .
>> Now in my view I would create a single list where there is  there are
>> both each others order by created.
>> Example
>>
>> Event 1    07/09/09
>> News 1    07/09/09
>> News 2    06/07/09
>> ......
>> ......
>> ......
>>
>> I would manage this list with paginate.
>> Is someone can suggest me a pattern  that I can use to do a thing like
>> this?
>> Many thanks

I'm sure Set class can help with this. I had an idea but it's not
quite there, I think.

Say these are your data (inner arrays would all contain more key =>
val, of course);

$events = array(
'Event' => array(
array('created' => '2007-10-02'),
array('created' => '1998-02-03'),
array('created' => '2001-04-30'),
array('created' => '2002-05-23'),
array('created' => '2003-07-21')
)
);
$news = array(
'News' => array(
array('created' => '2003-04-12'),
array('created' => '2003-10-24'),
array('created' => '2000-01-03'),
array('created' => '2000-01-05'),
array('created' => '2000-05-28')
)
);

I'd think that this would do it:.

$foo = Set::sort(
Set::merge($events, $news),
'{s}.{n}.created', 'desc'
);

But that returns an empty array.

--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: