Jason
Jason

Reputation: 1309

Inserting model(object) into table

I have a question regarding to codeigniter database class

according to user guide, I can easily insert a new row (or in other word, object) into my table by using

$data = array(
               'title' => $title,
               'name' => $name,
               'date' => $date
            );

However, is this possible for me to take a class (or model) that has title, name, date attribute (and possibly getter and setters for those attribute) and pass in a new object of that model class into $this->db->insert('user', $model);

Thanks in advance.

Upvotes: 0

Views: 74

Answers (1)

Pankaj Khairnar
Pankaj Khairnar

Reputation: 3108

Codeignier's Active record doesn't support sending Model's object to insert function, but you can use ORM library like Ignited Records or DataMapper if you want to use object orientation technoque for database operation

as per documentation you can send object of a class like this

 class Myclass {
     var $title = 'My Title';
     var $content = 'My Content';
     var $date = 'My Date';
 }

$object = new Myclass;    
$this->db->insert('mytable', $object); 

Upvotes: 1

Related Questions