Beispiel #1
0
 public function actionCategory()
 {
     $app = Yii::$app;
     $request = $app->request;
     $get = $request->get();
     $getString = $_SERVER['QUERY_STRING'];
     parse_str($getString, $getArray);
     $getUrl = $request->pathInfo;
     static::smartyAssign('getArray', $getArray);
     static::smartyAssign('getUrl', $getUrl);
     $alias = $get['alias'];
     $category = Category::getCategory($alias);
     if ($category) {
         $page = !empty($get['page']) ? is_numeric($get['page']) ? intval($get['page']) : 1 : 1;
         $size = !empty($get['size']) ? is_numeric($get['size']) ? intval($get['size']) : 10 : 10;
         static::smartyAssign('page', $page);
         static::smartyAssign('size', $size);
         $categoryArticleList = Category::getCategoryArticleList($alias, $page, $size);
         static::smartyAssign('category', $category);
         static::smartyAssign('categoryArticleList', $categoryArticleList);
         $recentArticleList = Article::getRecentArticleList(5);
         static::smartyAssign('recentArticleList', $recentArticleList);
         $categoryList = Category::getCategoryList();
         static::smartyAssign('categoryList', $categoryList);
         $this->showHtml();
     } else {
         $this->show404();
     }
 }
 public function actionGeneral()
 {
     $app = Yii::$app;
     $request = $app->request;
     if ($request->getIsDelete()) {
         $post = $request->post();
         $article = Article::findOne($post['id']);
         $article->status = 0;
         $result = array();
         if ($article->save()) {
             $result['code'] = 0;
         } else {
             $result['code'] = 1;
         }
         exit(json_encode($result));
     } else {
         $page = !empty($get['page']) ? is_numeric($get['page']) ? intval($get['page']) : 1 : 1;
         $size = !empty($get['size']) ? is_numeric($get['size']) ? intval($get['size']) : 10 : 10;
         $articleList = Article::getArticleList();
         $this->smartyAssign('articleList', $articleList);
         $categoryList = Category::getCategoryList();
         $this->smartyAssign('categoryList', $categoryList);
         $this->showHtml();
     }
 }
 public function actionCategory()
 {
     $app = Yii::$app;
     $request = $app->request;
     if ($request->getIsPost()) {
         $post = $request->post();
         $category = new Category(['scenario' => 'new']);
         $category->load($post);
         $category->save();
         $this->refresh();
     } elseif ($request->getIsDelete()) {
         $post = $request->post();
         $category = Category::findOne($post['id']);
         $category->status = 0;
         $result = array();
         if ($category->save()) {
             $result['code'] = 0;
         } else {
             $result['code'] = 1;
         }
         exit(json_encode($result));
     } else {
         $categoryList = Category::getCategoryList();
         $this->smartyAssign('categoryList', $categoryList);
         $this->showHtml();
     }
 }
Beispiel #4
0
 /**
  * Relations
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'cid'])->where(['status' => Category::STATUS_ACTIVE]);
 }
Beispiel #5
0
 /**
  * Relations
  */
 public function getParent()
 {
     return $this->hasOne(Category::className(), ['id' => 'pid'])->where(['status' => self::STATUS_ACTIVE]);
 }