コード例 #1
0
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     if ($pathInfo == 'blog' || $pathInfo == 'blog/index') {
         $params = [];
         return ['blog/blogposts/index', $params];
     }
     if (preg_match('%^blog/category/(.*)%', $pathInfo, $matches)) {
         $category = $matches[1];
         $blogCategory = BlogTerms::find()->where('slug LIKE :slug', [':slug' => $category])->one();
         if ($blogCategory) {
             $params = ['id' => $blogCategory->id];
             return ['blog/blogposts/category', $params];
         } else {
             return false;
         }
     }
     if (preg_match('%^blog/(\\w+)/(\\w+)/(\\w+)/(.*)%', $pathInfo, $matches)) {
         // check $matches[1] and $matches[3] to see
         // if they match a manufacturer and a model in the database
         // If so, set $params['manufacturer'] and/or $params['model']
         // and return ['car/index', $params]
         $date = $matches[1] . '-' . $matches[2] . '-' . $matches[3] . '%';
         $blogPost = BlogPosts::find()->where('date LIKE :date AND slug = :slug', [':date' => $date, ':slug' => $matches[4]])->one();
         if ($blogPost) {
             $params['id'] = $blogPost->id;
             return ['blog/blogposts/view', $params];
         } else {
             return false;
             // this rule does not apply
         }
     }
     return false;
     // this rule does not apply
 }
コード例 #2
0
 public function search($params)
 {
     $query = BlogTermsModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'type', $this->type]);
     return $dataProvider;
 }
コード例 #3
0
 public function run()
 {
     $model = BlogTerms::find()->orderBy('name')->all();
     return $this->render('categories', ['model' => $model]);
 }
コード例 #4
0
 /**
  * actionCreatecategory function.
  *
  * @access public
  * @return json array
  */
 public function actionCreatecategory()
 {
     Yii::$app->response->getHeaders()->set('Vary', 'Accept');
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = new BlogTerms();
     if ($model->load(Yii::$app->request->post())) {
         $model->type = 'category';
         if ($model->validate() && $model->save()) {
             return ['success' => true, 'model' => $model];
         }
     }
     return ['error' => $model->errors];
 }
コード例 #5
0
 /**
  * Updates an existing BlogPosts model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     BlogAssets::register($this->view);
     FilemanagerTinyAssets::register($this->view);
     $model = $this->findModel($id);
     $terms = new BlogTerms();
     $categories = BlogTerms::find()->termType()->orderBy('name')->all();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             BlogTermRelationships::deleteAll('post_id = ' . $model->id);
             $termRelations = new BlogTermRelationships();
             $categoryTerms = Yii::$app->request->post();
             if (isset($categoryTerms['categories'])) {
                 foreach ($categoryTerms['categories'] as $c) {
                     $termRelations->isNewRecord = true;
                     $termRelations->id = null;
                     $termRelations->post_id = $model->id;
                     $termRelations->term_id = $c;
                     $termRelations->save();
                 }
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model, 'terms' => $terms, 'categories' => $categories]);
         }
     } else {
         return $this->render('update', ['model' => $model, 'terms' => $terms, 'categories' => $categories]);
     }
 }
コード例 #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTerm()
 {
     return $this->hasOne(BlogTerms::className(), ['id' => 'term_id']);
 }
コード例 #7
0
 public function actionCategory($id)
 {
     $model = BlogTerms::findOne($id);
     return $this->render('category', ['model' => $model, 'module' => $this->module]);
 }