Welcome Guest, Not a member yet? Register   Sign In
Model concept question
#9

(This post was last modified: 01-16-2017, 09:06 AM by Wouter60.)

Why re-invent the wheel?
Avenirer has developed a great MY_Model class:
https://github.com/avenirer/CodeIgniter-MY_Model

You must put the MY_Model.php file in the application/core folder.
Then, create your own model in application/models and extend the MY_Model class.
Like this:

PHP Code:
class User_model extends MY_Model {
 
  //... your code here


With minimal setup, you can use the built-in functions of MY_Model.
Example:
PHP Code:
$this->load->model('user_model');
$this->user_model->where('city','London');
$this->user_model->order_by('address','ASC');
$users $this->user_model->get_all(); 

It even works with method chaining:
PHP Code:
$users $this->user_model->where('city','London')->order_by('address''ASC')->get_all(); 
Now, users is an array of objects with all the records that meet the 'where city = "London"' condition, in order of address. Easy as can be!
Reply


Messages In This Thread
Model concept question - by meSmashsta - 01-15-2017, 10:16 PM
RE: Model concept question - by venkat - 01-15-2017, 10:27 PM
RE: Model concept question - by meSmashsta - 01-15-2017, 10:40 PM
RE: Model concept question - by venkat - 01-16-2017, 12:40 AM
RE: Model concept question - by meSmashsta - 01-16-2017, 01:09 AM
RE: Model concept question - by venkat - 01-16-2017, 02:00 AM
RE: Model concept question - by meSmashsta - 01-16-2017, 02:20 AM
RE: Model concept question - by InsiteFX - 01-16-2017, 05:50 AM
RE: Model concept question - by Wouter60 - 01-16-2017, 09:04 AM
RE: Model concept question - by meSmashsta - 01-17-2017, 04:06 AM
RE: Model concept question - by InsiteFX - 01-17-2017, 04:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB