Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord is not updating data

Tags:

yii

Here is a piece 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 Files model contains a count field. The code is ok, and there are no warnings, but the save method is not working.

like image 241
Suleymanov Rashid Avatar asked Oct 07 '22 11:10

Suleymanov Rashid


1 Answers

try $file->getErrors() to display after save() and before redirect to see if there are no errors

this would show you what is the problem. Most common is you are not populating the dependencies required for a model to insert a row in database

to see it in well format use

CVarDumper::Dump($file->getErrors(),100,true)
like image 188
Afnan Bashir Avatar answered Oct 12 '22 11:10

Afnan Bashir