Welcome Guest, Not a member yet? Register   Sign In
Creating multiple instances of a model
#10

(04-28-2016, 09:51 AM)kilishan Wrote: Personally, I would separate the Customer entity from the model itself. What I mean is that I would have two classes: Customer and Customer_model. The model would be responsible for all interactions with the database. Then, the Customer class would represent a single customer. It would have any additional business logic needed inside of it, functions to get related entities, etc. You can have the query result object return custom classes, so your code would simplify into something like this:

Code:
// You need to load the class into memory somehow,
// unless you're using Composer and namespacing it...
$this->load->library('Customer');

// Load the model and the query results.
$this->load->model('customer_model');
$query = $this->customer_model->findActive();

// Returns an array of Customer instances.
$customers = $query->result('Customer');

You can create multiple instances of a library? I thought Libraries were singletons as well.
Reply


Messages In This Thread
RE: Creating multiple instances of a model - by Shawn - 05-24-2016, 07:40 PM



Theme © iAndrew 2016 - Forum software by © MyBB