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