我嘗試創建一個編輯視圖,該視圖允許用戶編輯名爲ABC的模型的條目。只要用戶打開某個行的編輯掩碼,它就應該鎖定該行。我在數據庫中有一個名爲'locked'的tinyint(1)值,它會這樣做。這裏是代碼的一部分。它發生在saveField方法上,我已經檢查過它。奇怪的是,因爲價值在正確的記錄上發生了變化!但不知怎的,它試圖做兩次相同的任務,我不知道爲什麼。saveField上的CakePHP空白條目
function edit($id = null) {
// select the
$this->ABC->id = $id;
$session = $this->Session->read();
$this->set('locked',false);
// save or read the data
if (empty($this->data)) {
$this->data = $this->ABC->read();
// locking
if ($this->data["ABC"]["locked"] == true) {
$this->set('usercanedit', false);
$this->set('locked', true);
} else {
$this->ABC->saveField('locked', true);
}
}
}
當我用這個替換saveField代碼(這當然是愚蠢的,只是爲了測試)它的作品。這不知何故證明編輯方法被調用兩次。一旦沒有參數或錯誤的參數。
if($this->ABC->id == 13)
$this->ABC->saveField('locked', true);
有人有想法嗎?
確定當您打開編輯面具調用方法編輯()只有一次? – riotera 2012-04-26 02:46:37