Example #1
0
 /**
  * Возвращает модель категории.
  * @param int $id идентификатор категории
  * @throws NotFoundHttpException в случае, когда категория не найдена
  * @return Post
  */
 public function getCategory($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested post does not exist.');
     }
 }
Example #2
0
 /**
  * Updates an existing Post model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'category' => Category::find()->all()]);
     }
 }
 /**
  * Updates an existing Post model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     // $post = $this->findModel($id);
     $model = $this->findModel($id);
     if (Yii::$app->user->can('updatePost', ['post' => $model])) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('update', ['model' => $model, 'category' => Category::find()->all()]);
         }
     } else {
         echo 'ddd';
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category 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.');
     }
 }
Example #7
0
 public function user_posts($id)
 {
     $posts = Posts::where('author_id', $id)->where('active', '1')->orderBy('created_at', 'desc')->paginate(5);
     $title = User::find($id)->name;
     $mydata = Category::where('status', 'y')->paginate(15);
     $posts->setPath('posts');
     return view('Blog::home')->withPosts($posts)->withTitle($title)->with('mydata', $mydata);
 }
Example #8
0
 /**
  * Просмотр категорий.
  * @param string $id идентификатор поста
  * @return string
  */
 public function actionCat($id)
 {
     $categoryModel = new Category();
     $category = $categoryModel->getCategory($id);
     return $this->render('index', ['category' => $categoryModel->getCategory($id), 'models' => $category->getPosts()]);
 }
Example #9
0
 public function init()
 {
     parent::init();
 }
Example #10
0
 /**
  * Category List
  * @return array
  */
 public static function getCategoryList()
 {
     $category = Category::find()->all();
     return ArrayHelper::map($category, 'id', 'title');
 }
 /**
  * Description: Return dynamic catefory for bind menu
  * By: Dhara
  * Date: 2-6-2016
  * @return type
  */
 public static function getCategoryMenu()
 {
     $cat = \App\Modules\Blog\Models\Category::where('status', 'y')->paginate(15);
     return $cat;
 }