Im trying to update a row in cakePHP 2.3.1.I have class Test extend AppModel with $validates array, and the Controller( simplified ) :
public function editstudent() {
if($this->request->data) {
$this->Test->stuId= $this->data['Test']['stuId'];
if ($this->Test->save($this->request->data)) {
$this->set('state',1);
}
}
The book said that :
Creating or updating is controlled by the model’s id field. If $Model->id is set, the record with this primary key is updated. Otherwise a new record is created:
As above I've set $this->Test->StuId but when I submit form it still shows :
Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'PRIMARY' SQL Query: INSERT INTO ........
As the error showed,the query still is INSERT not UPDATE So what do I have to do to update,pls help me out :(
EDIT : @thaJeztah I've edit my view like this :
class Test extends AppModel {
var $name= 'Test';
var $primaryKey= 'stuId';
public $validate= array(.......);
}
But it still show the same problem
Database Error Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'PRIMARY' SQL Query: INSERT INTO
cakePhp.tests(stuName,stuDoB,stuAdd) VALUES ('Đào Đức Anh', '2013-03-25', 'Kim Liên')
As you see the query is still INSERT not UPDATE,can you help me why this still happens :(
teststable? - dhofstet