/** * Updates an existing Category model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { if (!$this->is_access('category/update')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $model = $this->findModel($id); $CatRecommend = new CatRecommend(); if ($model->load(Yii::$app->request->post()) && $model->save()) { // 加入分类推荐 $CatRecommend->insertRecommend($model->cat_id, $_POST['Category']['recommend_type']); // 是否需要显示在导航栏 $Nav = new Nav(); if ($model->show_in_nav == 1) { $Nav->addData('c', $model->cat_id); } else { $Nav->delData('c', $model->cat_id); } Yii::$app->session->setFlash('success', '编辑成功'); return $this->redirect(['index']); } else { $model->recommend_type = $CatRecommend->catRecommend($id); Yii::$app->view->params['meta_title'] = '编辑分类'; $catList = $model->parent(0); return $this->render('update', ['model' => $model, 'catList' => $catList]); } }
/** * 修改分类 是否在导航栏显示 的状态 * @param $cat_id * @param int $status * @return bool|int */ public function show_in_nav($cat_id, $status = 1) { if (!in_array($status, [0, 1])) { return false; } $result = Category::updateAll(['show_in_nav' => $status], 'cat_id = :cat_id', [':cat_id' => $cat_id]); if ($result) { $Nav = new Nav(); if ($status == 1) { // 新增 $Nav->addData('c', $cat_id); } else { // 删除 $Nav->delData('c', $cat_id); } return true; } return false; }