If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Php oop

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-16-11, 10:13
jx12345 jx12345 is offline
Registered User
 
Join Date: Apr 2010
Posts: 51
Php oop

I'm building a invoicing system with php/mysql as part of a project to get my head round OOP, MVC & REST.

I have the following db tables:

customers: customer_id (pk), name, email
invoices: invoice_no (pk), date, amount, customer_id(fk)
invoice_items: item_id (pk), description, qty, cost, invoice_no (fk)

I currently have all traffic routed to index.php which then, depending on the HTTP method and the url routes the request to a relevant controller.

For example,
GET/invoices
is routed to InvoiceController::listResource();

POST/invoices
is routed to InvoiceController::createResource();

GET /invoices/1
is routed to InvoiceController::viewResource();

etc.

The controller class currently handles all the db stuff then loads a relevant 'template' for example: include 'invoice_view.php' to display the data to the user.

I'm thinking it would be better to get the db stuff out of the controller and have a class for each resource.

My question is as my invoice is related to both invoice_items and customers should my invoice object have both an array of invoice_item objects, and a customer object within it.

This would make a lot of my code simpler - i wouldn;t have to keep 'dipping into' the database but it seems like i'd be sticking quite a lot in memory each time i loaded an invoice.

hope that makes sense...

any comments very welcome...

ta

j
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On