Example #1
0
 public function run()
 {
     $items = Categories::getItemsByCategory($this->id);
     echo '<div class="row">';
     foreach ($items as $item) {
         echo ItemWidget::widget(['id' => $item['id'], 'classes' => $this->classes, 'orderby' => 'title']);
     }
     echo '</div>';
 }
Example #2
0
 public function getCategoriesSelect2($id)
 {
     $sql = 'SELECT id,name FROM {{%article_categories}} WHERE published = 1 AND id !=' . $id;
     $categories = Categories::findBySql($sql)->asArray()->all();
     $array[0] = \Yii::t('articles.message', 'No Category');
     foreach ($categories as $category) {
         $array[$category['id']] = $category['name'];
     }
     return $array;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categories::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parentid' => $this->parentid, 'published' => $this->published, 'access' => $this->access, 'ordering' => $this->ordering]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'image_caption', $this->image_caption])->andFilterWhere(['like', 'image_credits', $this->image_credits])->andFilterWhere(['like', 'params', $this->params])->andFilterWhere(['like', 'metadesc', $this->metadesc])->andFilterWhere(['like', 'metakey', $this->metakey])->andFilterWhere(['like', 'robots', $this->robots])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'copyright', $this->copyright])->andFilterWhere(['like', 'language', $this->language]);
     return $dataProvider;
 }
Example #4
0
 public function getCategory()
 {
     return $this->hasOne(Categories::className(), ['id' => 'catid'])->from(Categories::tableName() . ' AS category');
 }
Example #5
0
 /**
  * Return array for Category Select2
  * @return array
  */
 public function getCategoriesSelect2()
 {
     $categories = Categories::find()->orderBy('name')->all();
     $array[0] = Yii::t('articles', 'No Parent');
     foreach ($categories as $category) {
         $array[$category['id']] = $category['name'];
     }
     return $array;
 }
 /**
  * Finds the Categories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Categories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }