1

在我看来,我正在使用这样的方式删除记录

<?php  echo CHtml::link('Delete',"#", array("submit"=>array('delete', 'id'=>$data->id), 'confirm' => 'Are you sure?','class'=>'btn btn-danger icon_delete'));?>

如果我按下删除按钮,它会生成警报框,然后如果我单击确定,则不执行任何操作删除,这意味着(它不会进入控制器)任何人都可以帮忙

控制器

 public function actionDelete($id)
 {
 $this->loadModel($id)->delete();
 if(!isset($_GET['ajax']))
 $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('view'));
 }
4

1 回答 1

0

The code for deleting the record is fine only. I think you should check controller, may be you have not defined the action 'delete'. Just check it.

I think you should change the code in the delete action as follow pattern:

    $model = Your_modelClass name::model()->findByPk($id);
    $model->delete();
    $this->redirect(array('list'));

Here Your_modelClass name should be same as the model(or table, from where you want to delete the data). But make sure that you have created model also for your table.

And the 3rd line is optional, You can use it if want to redirect to any page(here list page).

Think it will help.

于 2013-01-21T10:25:36.207 回答