This one is a bit more for the dev team ... but since I doubt they
read this much, wonder if anyone else wants to chime in ...

One thing I'm struggling with is the lack of OOP on the part of the
models after a find, especially for a list.
Now, before I get flamed, let me explain what I mean.

If I do a `find('all')` I simply get a (possibly) multi-level
associative array. I don't have much of a problem with that, easy to
do typical PHP array function calls on that, but then I want to start
looping through and pulling records off of it and possibly doing some
extra stuff ...

Let's say I have an list of `PurchasedItems` for an Order form, each
PurchasedItem needs to have the taxes calculated. From what I've seen/
read, most do this in the View .. which might be all and good, but
doesn't seem very DRY or modular ... from an OOP standpoint, it would
make more sense to have a function called `calculate_subtotal()`
accessible from the View to do this. However, I have yet to find out a
way to do this, anything I've tried throws back an error ("Call to a
member function calculate_subtotal() on a non-object") .. obviously,
since it's an array, not an object. From what I've read, some are
suggesting looping in the Controller to calculate this ... so I'm
doing 2 loops? One in the Controller to calculate, and the other in
the View to display ... that doesn't make much sense.

Another head-scratcher is that in a `find('all')`, then subsequent
foreach loop, for associations, they're returned on the same level as
the object. Again, I'll explain ...

I've got a list of Webpages, each has a WebpageType. I do a
`find('all')` on the Webpages, I get something returned like:

Array
(
    [0] => Array
        (
            [Webpage] => Array
                (
                    [id] => 1
                    [user_id] => 1
                    [webpage_type_id] => 2
                    [url] => somewebsite.com
                )

            [WebpageType] => Array
                (
                    [id] => 2
                    [name] => Blog
                )

        )

....
)

Now in my mind, WebpageType should not be on the same level as Webpage
because it is a 'technically' member of Webpage (since it
"belongsTo") ... I would think the result would be more like:


Array
(
    [0] => Array
        (
            [Webpage] => Array
                (
                    [id] => 1
                    [user_id] => 1
                    [webpage_type_id] => 2
                    [url] => somewebsite.com
                    [WebpageType] => Array
                        (
                            [id] => 2
                            [name] => Blog
                        )
                )
        )

....
)

Taking this principle with the first one (where it's all OOP), from
the View I could then access this in a foreach with:

$webpage->WebpageType->name;


If anyone is still reading by this point (sorry it's so long),
hopefully you can shed some light.

Thanks.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to