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