这是我的一段代码
$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);
Files
模型包含count
字段。
代码没问题,没有警告,但是保存方法不起作用。
答案 0 :(得分:4)
尝试$file->getErrors()
在save()之后和重定向之前显示是否没有错误
这会告诉你问题是什么。最常见的是您没有填充模型在数据库中插入行所需的依赖项
以井格式使用
CVarDumper::Dump($file->getErrors(),100,true)