php - Can a model house multiple functions querying different domains? -
i have domain users connects user table, includes information username, first name, , last name.
then have domain emails, connects email table because user can have more 1 email. email table consists of fk connect user emails, , other fields address, status, etc.
should have different domains separate tables, combine functions, call domains, in models? or maybe can it's not best practice.
i new mvc thing , it's hurting brain right now. maybe, hasn't explained enough.
question: when mention having "domain", referring user model, , email model? or design pattern?
also, (but depends on application) having email database logic inside users model more logical (to me), since don't think going add email addresses without creating user. is, email model depends on user model, , perhaps only on user model, maybe should combined?
the way it:
put database logic inside models assume way have done it.
create library or class place business logic of application concerns users. (for example, uploading image, or connecting web service, should not in model if follow standard codeigniter models should contain database logic, that's why create class handle cases)
- now, when want create user, inject models in library (you @ controller level), , call abstract method
create_user()
class users extends controller { public function create() { // these in constructor! $this->load->model('users'); $this->load->library('users_logic'); $this->users_logic->set_model($this->users); // and/or: $this->users_logic->set_email_model($this->email_model); if ($this->input->post('name')) { $this->users_logic->create(); } } }
Comments
Post a Comment