Example #1
0
 public function actionTypedel($id)
 {
     $model = GoodsType::findOne($id);
     if ($model->delete()) {
         Attribute::deleteAll('type_id = :type_id', [':type_id' => $id]);
         Yii::$app->getSession()->setFlash('info', '操作删除成功!');
         return $this->redirect(['typelist']);
     }
 }
 /**
  * Deletes an existing GoodsType model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if (!$this->is_access('goodstype/delete')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $this->findModel($id)->delete();
     // 删除类型的属性
     \common\models\Attribute::deleteAll(['cat_id' => $id]);
     return $this->redirect(['index']);
 }
 /**
  * 批量删除
  */
 public function actionDeleteall()
 {
     if (!$this->is_access('attribute/delete')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     if (Yii::$app->request->isPost) {
         $attr_id = $_POST['id'];
         if (is_array($attr_id)) {
             $attr_id = '(' . implode(',', $attr_id) . ')';
             Attribute::deleteAll('attr_id in ' . $attr_id);
             Yii::$app->session->setFlash('success', '删除成功');
         }
     }
     $this->redirect(Yii::$app->request->getReferrer());
 }