如何将我想要删除的记录设置为1而不是删除记录本身?我现在正在使用Yii框架,我是新手。我有CGridview更新,查看和删除。在删除时,我希望用户将他们想要删除的记录设置为1,而不是删除整个记录。提前感谢您提供的任何帮助!
答案 0 :(得分:0)
只需更新控制器中的actionDelete
:
public function actionDelete($id)
{
$model = $this->loadModel($id);
$model->is_deleted = "1"; //assuming is_deleted is the column name
$model->update();
// 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'));
}
并且您的模型search
用于删除is_deleted = 1
项,您可以:
//.... rest of your code above
$criteria->addCondition("is_deleted != 1");
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));