Model and Active Record with private properties. |
Since you mentioned Active Record, I'm assuming you're using CI 2 instead of CI 3.
In your model, $this->db refers to CI's database library, so, if you wanted to insert something using CI's Active Record methods, you would use Code: $this->db->insert('table_name', $data); http://www.codeigniter.com/userguide2/da...tml#insert $data can be an object or an array, but, if it's an object, the object must have a set of public properties which match the column names in your database (if it's an array, the keys in the array would match the column names in the database). The message you are alluding to, though, implies you are performing an update via Code: $this->db->update('table_name', $data); http://www.codeigniter.com/userguide2/da...tml#update Whether performing an insert or an update, you can either supply the $data to the insert()/update() method, or use the set() method to set individual columns: Code: $this->db->set('column_name', $value); (The set() method is documented on the same page as the insert() and update() methods, just scroll up from update() or scroll down from insert().) In any case, all properties and methods defined within your model are available to any other method in your model. The access modifiers (public/protected/private) only define whether other classes can access those properties/methods. http://php.net/manual/en/language.oop5.visibility.php |
Messages In This Thread |
Model and Active Record with private properties. - by rafaelwendel - 04-27-2015, 05:26 PM
RE: Model and Active Record with private properties. - by Avenirer - 04-27-2015, 11:22 PM
RE: Model and Active Record with private properties. - by mwhitney - 04-28-2015, 09:24 AM
RE: Model and Active Record with private properties. - by rafaelwendel - 04-28-2015, 03:08 PM
RE: Model and Active Record with private properties. - by mwhitney - 04-29-2015, 11:13 AM
|