删除前我遇到yii update status的问题。如果产品已按顺序设置,我想使产品的状态= 0。然后,如果产品没有按顺序设置,他们将删除它。产品的检查已经按顺序设置或者没有做好..但是当程序进入(if($ dorders> 0))时它不是错误,但产品的状态仍然是1 ..没有变为0 ..请帮助任何人..谢谢
public function actionDelete($id)
{
$criteria = new CDbCriteria;
$criteria->condition = 'id_product="'.$id.'"';
$dorders=DOrder::model()->count($criteria);
if($dorders>0){
$model=$this->loadModel($id);
$model->status=1;
$model->save();
}
else{
$this->loadModel($id)->delete();
unlink('uploads/product/'.$id.'.jpg');
}
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
答案 0 :(得分:1)
检查错误消息:
$model=$this->loadModel($id);
$model->status=1;
$result = $model->save();
var_dump($result);
print_r($model->getErrors());