2013-05-10 43 views
0

我想更新表Scale中的某個字段。我有一個數組:Model :: save()返回false,即使所有數據都正確保存

$s = array(
    'id' => '1', 
    'name' => 'NAME', 
    'description' => 'DESCRIPTION', 
    'type' => 'custom' 
); 

和保存它像這樣:

$this->Scale->save($s); 

我沒有任何notofication收到一個錯誤。這不是驗證問題,因爲我在這個模型中沒有驗證。即使我有一個錯誤,所有數據保存正確。

那麼爲什麼save方法返回false呢?

+0

什麼錯誤? – fullybaked 2013-05-10 09:01:56

+0

沒有正式的錯誤。正好當我檢查數據是否已正確保存時 - 它返回我FALSE – Ziemo 2013-05-10 09:08:33

+0

您是否可以顯示您的if語句。 – 2013-05-10 09:10:28

回答

4

通過評論,你有你的if結構不正確。

<?php 
if ($this->Scale->save($s)) { 
    throw new NotSaveException(); 
} 

$this->Scale->save()將返回true這將反過來拋出異常。您需要在else

if塊應該是例外...

<?php 
if ($this->Scale->save($s)) { 
    // deal with success 
} else { 
    throw new NotSaveException(); 
} 
+0

WOW ...我忘記把''!'語句寫成:if(!$ this-> Scale-> save($ s))'。謝謝 ! :D – Ziemo 2013-05-10 09:37:04

+2

@Ziemo,這就是在提出問題時包含所有*相關*代碼的原因:) – thaJeztah 2013-05-10 22:31:53

相關問題