1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | classDeleteActionextendsCAction { public$pk='id'; public$redirectTo='index'; public$modelClass; functionrun() { if(empty($_GET[$this->pk])) thrownewCHttpException(404); $model= CActiveRecord::model($this->modelClass)->findByPk($_GET[$this->pk]); if(!$model) thrownewCHttpException(404); if($model->delete()) $this->redirect($this->redirectTo); thrownewCHttpException(500); } } |
1 2 3 4 5 6 7 8 9 | functionactions() { returnarray( 'delete'=>array( 'class'=>'DeleteAction', 'modelClass'=>'User',//model名字 ); ); } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |