我試着去更新在CakePHP 2.3.1.I一排有Test類擴展AppModel與$驗證陣列, 和控制器(簡體):更新行
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);
}
}
書中說:
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:
正如上面我已經設置$這個 - >測試 - > StuId但是當我提交表單它仍然顯示:
Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'PRIMARY' SQL Query: INSERT INTO ........
作爲錯誤顯示,查詢仍然被夾不更新 那麼我一定要做到及時更新,請幫我:(
編輯:@thaJeztah我已經編輯我的看法是這樣的:
class Test extends AppModel {
var $name= 'Test';
var $primaryKey= 'stuId';
public $validate= array(.......);
}
但它仍然顯示了同樣的問題
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')
正如你所看到的查詢仍在INSERT不更新,你可以幫我爲什麼仍然發生:(
的評論刪除
$useTable
屬性您的'tests'表的結構如何? – dhofstet 2013-03-22 07:04:31'tests'表有5個字段: 主鍵:stuId和4個字段:stuName,stuSex,stuDoB,stuAdd – 2013-03-22 10:51:04