Add new record in database, using CakePHP

Posted by nikola, With 0 Comments, Category: CakePHP,

Adding new record in database, without raw SQL, but using CakePHP's methods.

Often is needed to add new record in database, when you can not use simple $this->Model->save($this->data) method, and when you do not want to use raw MySQL functions.

You can add it on next way:

$this->Model->create();
 $this->Model->set('field_1', $value_1 );
 $this->Model->set('field_2', $value_2 );
 $this->Model->set('field_3', $value_3 );
 $this->Model->set('field_4', $value_4 );
 // etc
 $this->Model->save();