Ejemplo n.º 1
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         if (($id = $this->get('id', null)) !== null) {
             $ids = is_numeric($id) ? array($id) : explode(',', $id);
             // delete one or multiple objects given the list of object IDs
             $result = $this->api('XUser.AdminUserGroup.delete', array('ids' => $ids));
             if (errorHandler()->getException() == null) {
                 // only redirect user to the admin page if it is not an AJAX request
                 if (!Yii::app()->request->isAjaxRequest) {
                     $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
                 } else {
                     echo 'Items are deleted successfully';
                 }
             } else {
                 // redirecting with error carried ot the redirected page
                 if (!Yii::app()->request->isAjaxRequest) {
                     user()->setFlashErrors(errorHander()->getErrors());
                     $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
                 } else {
                     //This won't work for grid as its jquery.gridview.js alert ajax content
                     //echo errorHandler()->getErrorMessages();
                     echo errorHandler()->getException()->message;
                 }
             }
         } else {
             throw new CHttpException(400, Yii::t('Xpress.XUserGroup', 'Cannot delete item with the given ID.'));
         }
     } else {
         throw new CHttpException(400, Yii::t('Xpress.XUserGroup', 'Invalid request. Please do not repeat this request again.'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         if (($id = $this->get('id', null)) !== null) {
             $ids = is_numeric($id) ? array($id) : explode(',', $id);
             // delete one or multiple objects given the list of object IDs
             $result = $this->api('Admin.Module.delete', array('ids' => $ids));
             if (errorHandler()->getException() == null) {
                 // only redirect user to the admin page if it is not an AJAX request
                 if (!Yii::app()->request->isAjaxRequest) {
                     $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
                 } else {
                     echo CJavaScript::encode(array('msg' => Yii::t('Xpress.Common', 'Items are deleted successfully.')));
                 }
             } else {
                 // redirecting with error carried to the redirected page
                 if (!Yii::app()->request->isAjaxRequest) {
                     Module()->setFlashErrors(errorHander()->getErrors());
                     $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
                 } else {
                     echo errorHandler()->getException()->message;
                 }
             }
         } else {
             throw new CHttpException(400, Yii::t('Xpress.Common', 'Cannot delete item with the given ID.'));
         }
     } else {
         throw new CHttpException(400, Yii::t('Xpress.Common', 'Invalid request. Please do not repeat this request again.'));
     }
 }