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()
,查看是否没有错误提示!在数据库中有一个字段是空的,但在规则中它是需要的,我得到了一个错误!然后将其标记为答案,这样,如果有人遇到问题,他或她知道该怎么办:)