Welcome Guest, Not a member yet? Register   Sign In
Model and Helper Functions
#1

[eluser]Dushan[/eluser]
I would like to get some opinions on what people use models and helpers for in these scenarios.

1. Do you use models ONLY as an interface with the database (select, insert, update, delete). If so, where do you put functions that manipulate database outputs: controllers, helpers...?

2. Do you have other functions that perhaps manipulate the data in models too?

3. Do you create a single model for each table? If so, do you join data by processing multiple model outputs in PHP? If so, would you do that in the controller, one of the models (if so how do you choose), or a helper function?

4. Do you alternately have models that work with multiple tables (expl. user, userInvoice, and invoice tables and call the model something like user_invoices)?

Right now I have a model called 'user' that runs queries for users, but also joins a lot of other tables to get relevant user data. That model also does some of the processing of the data it returns too. It's a bit messy. My controllers are clean, but it's hard to to know exactly what belongs to what model and where do functions for model data go.

Many thanks in advance!!!
#2

[eluser]WanWizard[/eluser]
1. No, I use models to interact with any data collection (databases, flat files, key-value stores, REST/SOAP/XML services, etc...).
2. If I have manipulation methods that have to or can be reused, I'll put them in a library, which is then called from the methods.
3. Yes. But I use Datamapper ORM, which works that way.
4. Not very often, as Datamapper handles all relationships. But it happens sometimes, for example if I need to split a table in two, but need to present it to the application as one.
#3

[eluser]Dushan[/eluser]
I am not working with a ORM, although I'll look into DataMapper ORM. Thanks.
ORM doesn't appear to be a part of the CodeIgniter core, so I'm sure that there are a lot of guys not using it. How do they tackle these issues?




Theme © iAndrew 2016 - Forum software by © MyBB