John David Anderson (_psychic_) wrote:
> On Jul 10, 2006, at 4:44 PM, [EMAIL PROTECTED] wrote:
>
> >
> > I doing research for a new framework for my project, I came across the
> > concept of the Hierarchical Model View Controler pattern.  I've only
> > found one php framework that claims to support this (Claw).  It
> > makes a
> > whole lot of sense to me and I was wondering if Cake supported this
> > (or
> > could it be extended easily if I needed to).
> >
> > If this is unfamiliar concept, it means basicaly that you can easily
> > embed MVC "components" inside one another.  Part of what makes this
> > work is a method for chaining them together and allowing you to
> > specify
> > on the URL arguments for multiple components.
> >
> > So if you had a page that contained an MVC component for "Lead" and
> > one
> > for "Notes", you could do things like this:
> > http://domain.com/view.php/lead/id.123/notes/page.2 which would give
> > you the lead of id 123 with the second page of notes.
> >
> > Does that make any sense?
>
> Not to me, at least. :)

Lets say I created an MVC triad of objects that represents the Lead
table in my database.  So then I could have a page with that MVC
"component" on it, and it would show one lead record from my Lead
table, with the URL argument "lead_id" being used as the primary key.
Lets say also that there's a lot of data associated with one lead
(multiple addresses, properties owned, etc) and it will need to be
paged.
So my url might be something like: lead_view.php?lead_id=42&page=2.

OK that's simple basic no brainer stuff, right?

Now lets say for that lead, I want to show all the notes from the Notes
table, where the lead_id on each record is equal to the lead_id.  So I
have another MVC triad of objects for the Note table.  It also has some
arguments that can be specified, notably a 'page' setting because there
could be hundreds of notes.  On its own page, it might look like:
notes_view.php?lead_id=42&page=3.

So I want these both on one page.  There would be another MVC triad
that would be the parent of both components.  In this MVC, there may
not be any real Model because its just going to include the lead and
note objects.  But the View object will have a page level template that
the lead and notes are embeded into.  And the controler here is going
to understand how to take the URL and make sure both lead and notes get
the right args...  because they both have a 'page' argument, that's a
conflict.  Lead_id is the same, of course..

So you could make sure every component uses differently named
arguments, ie 'notesPage' and 'leadPage'.  Of course, this would break
if you had two of the same component..

Or you could have a url that looks something like this:
lead.php/lead_id.42/lead/page.2/notes/page.3

the MVC component on lead.php knows that both the lead and notes
components expect a lead_id and so passes that on to them.  It also
knows that 'page.2' is hte argument for 'lead' and that 'page.3' is for
'notes'.

I am not sure I am doing justice to the method since I have not used it
(yet) myself, but it makes sense.  Apparently its a well known method
in other language circles (java) but has not been generaly picked up by
php people yet.

>
> > The other concern I have is with how Cake interfaces to the database.
> > I've always thought it didnt make a lot of sense to directly map
> > objects to the database -- they just arent the same thing, after all.
> > After reading some articles on it, I realize I am not the only one to
> > think this.
>
> I've always thought of database tables as objects that relate to an
> application. Some tables arent (like join tables), but for the most
> part, a table should reflect an object or domain in your application.
>
> That's why they call them RDBMS's after all, but everyone looks at
> things differently.

Relational Databases are really very different from Objects.  A table
is more like an array than an object.

>
> > I figure for 90% of my project, the typical Object Relational Mapping
> > method would probably work fine, to create the CRUD type pages needed.
> > But that last 10% would be a total bitch to create.  This is the same
> > problem I have with Codecharge Studio.
>
> What sort of things are happening in the 10%?

I have a component that lists leads from the lead table.  When listing
leads, though, I may need to JOIN with multiple other tables to get all
the data for each lead.  The columns displayed in teh final HTML are
user settable.  So, for each lead, it may need to be joined with, say,
the notes table to get the latest note, the user table multiple times
to get the people assigned to that lead, the conditions for that lead,
etc.

The columns desired are stored in a few tables.  So I have a query that
loads up the 'view' and all the 'fields'.  These do map to objects.
Once loaded, I can call the method on the view object to generate the
SQL for the lead list.  Each of the field objects in the view object
knows what table needs to be joined and what needs to be added to the
FROM and WHERE parts.  So that big SQL statement is generated, and then
passed to the lead list object where it pulls in all the data and lists
it (the view object's field objects also know how to render themselves
and are used here too).

I am not sure how this maps to what Cake has built in.  It seems like
my little view/field object system probably does map directly to the
tables (and yes, I could take the resulting SQL and literaly make it a
VIEW in MySQL and then not regenerate it each time, making things a bit
faster) but the SQL it generates for the lead list seems completely
different from how most ORM systems work.  What I dont want is 1000
lead objects, each with 50 other objects for each bit of data,
resulting in who knows how many separate SQL queries...

>
> > It seems to me that the best method would be not to try and make
> > everything in teh database into an object, and maybe use a combination
> > of objects and list processing (after all, database tables are just
> > lists/sets of data, not objects).
>
> Well, Cake actually returns results in array form right now.
>
> > So for example, in cake, is it goign to create an object for every row
> > I fetch from the database?
>
> No. It will create an object that fetches data from your store, though.
>
> >   How easy is it to customize if I want to
> > have my object for a table but internaly it manages the rows as an
> > array?
>
> You can always override (or extend) methods or write your own model
> methods if you want to. Its all OOP. Besides, I think Cake returns
> data how you'd like. Have you used it yet?
>
> > Can cake create "smart" SQL queries that will pull all the data needed
> > in one query that ends up as several objects?
>
> Not sure what you mean by "smart", but models can be associated in
> Cake. So if I tell it my Supervisor hasMany Peons, bringing up a
> Supervisor record could automagically bring up its associated Peon
> records as well.
> 
> -- J


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

Reply via email to