public function actionNews_second() { if ($_GET['id']) { $id = $_GET['id']; } if ($_GET['pid']) { $pid = $_GET['pid']; } $category_name = \backend\models\Category::findOne(['id' => $pid])->title; $second_name = \backend\models\Category::findOne(['id' => $id])->title; $infos = \common\models\cms\Article::find()->where(['category_id' => $id])->asArray()->all(); return $this->render('news_second', compact("infos", "category_name", "second_name")); }
public function save() { if (!$this->validate()) { return false; } $model = new Category(); if (!empty($this->id)) { $model = Category::findOne($this->id); } $model->setAttributes(['parent' => $this->parent, 'link' => $this->link, 'title' => $this->title, 'published' => $this->published, 'meta_description' => $this->metaDescription, 'meta_keywords' => $this->metaKeywords, 'showPopular' => $this->showPopular, 'showSimilar' => $this->showSimilar, 'indexed' => $this->indexed]); if ($model->save(false)) { $this->id = $model->id; } return !empty($this->id); }
public function actionCreate() { $model = new Category(); $roots = ArrayHelper::map(Category::find()->roots()->all(), 'name', 'name'); if ($model->load(\Yii::$app->request->post())) { $post = \Yii::$app->request->post('Category'); if ($post['parent'] == null) { $parent = new Category(['name' => $post['name']]); $parent->makeRoot(); } else { $parent = Category::findOne(['name' => $post['parent']]); $child = new Category(['name' => $post['name']]); $child->appendTo($parent); } } else { return $this->render('create', ['model' => $model, 'roots' => $roots]); } }
/** * Finds the CategoryModel model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CategoryModel the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 删除子类 */ public function actionDelcatetwo() { $identity = Identity::checkIdentity('delcatetwo', '/app-backend/backend/category/delcatetwo'); if (is_array($identity)) { return $identity; } $request = \Yii::$app->request; $categoryId = intval($request->get('categoryId', 0)); $category = Category::findOne($categoryId); if ($category) { //删除该二级分类与产品的关联 \Yii::$app->db->createCommand()->delete('category_product', 'categoryId=' . $categoryId)->execute(); //删除该二级分类 $category->delete(); } return ['code' => 0, 'msg' => 'ok']; }