2013-05-10 69 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

相关问题