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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With