ActiveRecord does not update data

Here is a snippet of my code

$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);

The model Filescontains a field count. The code is OK and there are no warnings, but the save method does not work.

+5
source share
1 answer

try $file->getErrors()displaying after saving () and before redirecting to see if there are any errors

this will show you what the problem is. The most common is that you do not fill out the dependencies required for the model to insert a row into the database

to see it in a convenient format

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

All Articles