Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Yii ActiveRecord未更新数据_Yii - Fatal编程技术网

Yii ActiveRecord未更新数据

Yii ActiveRecord未更新数据,yii,Yii,这是我的一段代码 $file=Files::model()->findByPk($id); if($file == null) { throw new CHttpException(404,'Not found'); } $count = $file->count; $count++; $file->count = $count; $file->sa

这是我的一段代码

$file=Files::model()->findByPk($id);   
if($file == null) {
     throw new CHttpException(404,'Not found');   
}
$count = $file->count;           
$count++;                             
$file->count = $count;           
$file->save();                                      
$this->redirect(Yii::app()->request->hostInfo."/".$file->path);
文件
模型包含一个
计数
字段。 代码正常,没有警告,但保存方法不起作用。

尝试
$file->getErrors()
在保存()之后和重定向之前显示,以查看是否没有错误

这会告诉你问题出在哪里。最常见的情况是,您没有填充模型在数据库中插入行所需的依赖项

要以良好的格式查看它,请使用

CVarDumper::Dump($file->getErrors(),100,true)

尝试在保存()之后和重定向之前显示
$file->getErrors()
,查看是否没有错误提示!在数据库中有一个字段是空的,但在规则中它是需要的,我得到了一个错误!然后将其标记为答案,这样,如果有人遇到问题,他或她知道该怎么办:)