In MVC-Model View Controller design you implement the model to work seperately and contain buisness logic, pulling information down from the database.
I struggle so much with the design of implementing a good model. I know what information needs to be pulled down from the database, I just don't know the best way to implement it. I think of the model as the program API and I overload myself with questions like
- What if I need to sort the fields?
- What if I need to select by a certain username/id?
- What if I need to group by a particular field?
- How badly will the performance be affected if I'm selecting * just incase the calling function might need any of the information pulled down?
My API/Model becomes extremely bloated, having seperate functions and queries (just slighlty tuned/changed) for each function
$cart->getShoppingCart() $cart->getShoppingCartSortByTitle() $cart->getShoppingCartGroupByItemType()
I feel this makes the model extremely bloated and very tied, creating a lot of duplicated code. It might be better having this kind of model;
A better idea
'title, price' is the mySQL fields you can select, obviously being validated by the
getItems() function. That way it's not only restricted to returning certain fields.
- How could I achieve this?
- Is this truly a good model?
- Are there any other things you guys could suggest?
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki