public function deleteBar($id) { // $model=Bar::find()->where(['id'=>$id])->andWhere(['<>','isTop','1'])->one(); $model = Bar::find()->where(['id' => $id])->one(); if (!$model) { return false; } //子级 if ($model->isTop == 1) { $parent = Bar::findOne(['id' => $model->parentBar]); $parent->count = intval($parent->count) - 1; $parent->save(); } // $son=Bar::find()->where(['parentBar'=>$id])->all(); // if($model->delete()) if ($model->delete()) { return true; } return false; }
public function actionEditbarlist() { $user = new AdminUser(); if (!$user->checkUserIsLogin()) { $this->redirect(Variable::$home_url); return; } // $form=new BarForm(); // $req=Yii::$app->request;//创建一个请求对象 // $form->setScenario('update'); // if($form->load($req->post()) && $form->validate()){ // print_r($form); // } // $form->setScenario('update'); $req = Yii::$app->request; //创建一个请求对象 $id = trim($req->get('id')); if (!is_numeric($id) || $id == 0) { $this->redirect(Variable::$barIndex_url); return; } $barModel = Bar::findOne($id); $barListModel = Bar::find()->where(['parentBar' => $id])->all(); return $this->render(Variable::$editBarList_view, ['barModel' => $barModel, 'barListModel' => $barListModel]); }