Thanks for the responses.
Let me explain why, in my situation, this approach doesn't seem to
scale.
I'm talking about displaying various statistics from a DB,
including aggregate functions (SUM, MAX, etc), for every week in a
given month.

In terms of passing this to a page, the obvious data structure would be
traversed something like this:

foreach week  // so we see the same stats for each week in a month
    foreach user    //display stats for each user
        foreach project
            // display the how long the user spent on that project in
that week,
             //i.e aggregate SQL commands


I can provide more info if necessary, but I think that's enough to see
that the level of nesting of such an array won't make for nice code.

There's also no natural way to generate this data structure via SQL
queries alone,
so not only am I going to have to have a nasty loop in my view,
my controller has one as well, to convert the DB results into this!

If you're thinking that I'd have this problem outside of Cake, you're
right to an extent,
but there's a few aspects of cake that actually make this trickier
compared to mysql_query():

- Each row in a results set as itself 2 dimensional,
i.e instead of

array('userName'=>'bob','hours'=>5, 'projectName'=>'Rich Client')

 I get

array(
        0=>array ('hours'=>5), //sql aggregates get put in 0
        'Users'=>array('userName'=>'bob'),
        'project'=>array('projectName','Rich Client's Software')
        // ... other tables
)

So, remembering I get one of each of these per row,
and these are displayed for each week,
that's two more levels of nesting!
How many dimensions deep am I now?!


Also, in plain PHP (and indeed in some generally inferior PHP MVC
frameworks)
Views are allowed to call their corresponding controllers -
a few method calls in these loops ( for example
$controller->getStatsByUser($userName))
would reduce complexity and improve clarity - and because I have to
play with this data structure
in both my Controller and my view, such method calls would clean up my
code all over my app!

Until CakePHP returns objects (I really hope that's v2), I've thought
of (but not yet tried) one possible PHP5 solution - create objects on
the fly, so the views can get complex objects without needing loads of
classes defined and included.

Has anyone had to deal with displaying DB results of this level of
complexity?
Is there a better way I'm just not seeing?

If you're still reading this rant, thanks, and thanks to all the Bakers
in general.


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