I know this is a long post, i'm sorry. I'm just trying to get advice
on how to structure this code the right way. Alright, I've been
programming php off and on for a few years now, but i'm new to cakephp
1.2. I'm working on a project that involves a shopping cart for
ordering food. After talking to a friend of mine he explained it would
be best to design the shopping cart ordering process using a concept
called 'LineItems'. This concept pretty much says that you split the
order into 'lines' and each lineitem contains a product the person
ordered, and all the information about that product, (the quanitity,
the price, the name of the product, etc, etc). Then an 'order' is the
collection of Lineitems for that user. LineItems and orders are
associated with an 'order_id'. That way you look up an order from the
'orders' table using the 'order_id' and grab all of the assicated
"LineItems" with that order_id as the prmary key. okay so good so far.
Now the problem is the how do i translate this to Model View
Controller terms? The way i have things set up now is:

Controllers:
The user will be able to place multiple orders at once (orders for
future dates, and orders for that day). So right now i'm only working
with placing a single order with a controller called
'singleOrderController"

Models:
Then I have an 'order' model which writes to an 'orders' database
table
Then i have a 'LneItem' model that writes to a 'LineItems" database
table

Assocations
order->HasMany 'LineItem'
LineItem->BelongsTo 'order'

Database tables:
menuItems -> contains a list of food items offered by the company
lineItems-> contains a list of menuItems that user has ordered, the
quanity etc. AND the 'order_id'
orders->contains the "order_id" and the 'order_number'

so the code i have to do the processing so far is

CODE

foreach ($this->data['menuitems'] as $id => $quantity){
               if($quantity>0){ //and is numeric
                   $this->LineItem->create(array("order_id" => $this-
>order->data['order_id'], "quantity"=>$quantity, "menuitem_id"=>$id));
                   $this->order->save($this->LineItem->data);
               }


So the way this works is it grabs 1 line of input from the post data,
and assigns it to a lineitem, then it *HAS* to save the lineitem to
the database or else it erases it with new content. To me this just
seems stupid. The way that i would like to code this is to have an
order be an object, containing lineitems which are objects as well.
Then once you have ALL The information, you parse the data and insert
it into a database. But that doesn't seem to follow the model view
controller design pattern. Am i just not doing this right, or are
there a lot of concept behind the model view controller that i'm not
understanding? if someone could tell me how they would code this for
the best flexibility in mind, PLEASE i'm looking for ANY answers as to
how i'm messing this up, and how to design this better.

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

Reply via email to