Hi Chris -

Thanks for ideas.  Here's my implementation based on your suggestion:

function logs() {
        $clientLogs = $this->ClientLog->findAll(null, null,
'ClientLog.created DESC', 15);
        $pubLogs = $this->PubLog->findAll(null, null, 'PubLog.created DESC',
15);
        $logs = array();

        foreach($clientLogs as $clientLog) {
                $logs[$clientLog['ClientLog']['created']] = array('message' =>
$clientLog['ClientLog']['message']);
        }

        foreach($pubLogs as $pubLog) {
                $logs[$pubLog['PubLog']['created']] = array('message' =>
$pubLog['PubLog']['message']);
        }

        krsort($logs);
        $this->set(compact('logs'));
}

One immediate problem that presents itself is duplicate dates which
would overwrite the $log keys, however, as your signature suggets "I
just built it, damnit!"  Its Friday night and time for a beer!

Thanks for your help, Chris.  I'm still open to other suggestions as
well...


On Aug 31, 7:46 pm, "Chris Hartjes" <[EMAIL PROTECTED]> wrote:
> On 8/31/07, McFadly <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hello Bakers,
>
> > I have two Models in my database that contain log data.
>
> > ClientLog (id, client_id, message, created)
> > PubLog (id, pub_id, message, created)
>
> > I would like to have a "Dashboard" page similar to Basecamp or
> > Facebook, where all my log items show up in sequence according to
> > their created date, regardless of which model they came from.
>
> > What do you think is the best way to accomplish this?  At the model
> > level with a custom SQL query?  Or at the controller / view level with
> > an array function?
>
> I think you'd have to do a combination of both:
>
> 1) pull in the log entries for both ClientLog and PubLog, iterating
> through the result sets and creating another array that has the log
> entry date as the key and (for example) the log entry itself as the
> value, ending up containing data from both ClientLog and PubLog.
> 2) sort the resulting array of date=>entry values by date so you have
> a list sorted by date
> 3) pass that array to your view
> 4) display the view in your dashboard
>
> The reason I suggest this is because I do not know of another way to
> easily pull data from both those models with the relationship you
> describe.  If anyone else has a better way, I'd like to see it as
> well.
>
> Hope that helps.
>
> --
> Chris Hartjes
> Senior Developer
> Cake Development Corporation
>
> My motto for 2007:  "Just build it, damnit!"
>
> @TheBallpark -http://www.littlehart.net/attheballpark
> @TheKeyboard -http://www.littlehart.net/atthekeyboard


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to