CGridView中实现批量删除

阅读更多

1,CGridView中的columns添加

array(
                        'selectableRows' => 2,
                        'footer' => '',
                        'class' => 'CCheckBoxColumn',
                        'headerHtmlOptions' => array('width'=>'33px'),
                        'checkBoxHtmlOptions' => array('name' => 'selectdel[]'),
                ),

 作用是添加多选框

2.js代码

 3.Action

public function actionDelall()
        {
                if (Yii::app()->request->isPostRequest)
                {
                        $criteria= new CDbCriteria;
                        $criteria->addInCondition('id', $_POST['selectdel']);
                        Words::model()->deleteAll($criteria);//Words换成你的模型
                        
                        if(isset(Yii::app()->request->isAjaxRequest)) {
                                echo CJSON::encode(array('success' => true));
                        } else
                                $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
                }
                else
                        throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
        }

 文章来源于:http://www.yiichina.com/forum/topic/469/

你可能感兴趣的:(yii,php)