コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categories::find();
     $query->joinWith('parent');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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, 'state' => $this->state, 'access' => $this->access, 'ordering' => $this->ordering]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'parent.name', $this->parentid])->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;
 }
コード例 #2
0
 /**
  * Return an array with the user roles
  * @return array
  */
 public function getRoles()
 {
     $sql = 'SELECT name FROM {{%auth_item}} WHERE type = 1 ORDER BY name ASC';
     $roles = Categories::findBySql($sql)->asArray()->all();
     $array = ['public' => 'Public'];
     foreach ($roles as $role) {
         $array[ucwords($role['name'])] = ucwords($role['name']);
     }
     return $array;
 }
コード例 #3
0
ファイル: Items.php プロジェクト: vladkukushkin/yii2-articles
 public function getCategory()
 {
     return $this->hasOne(Categories::className(), ['id' => 'catid'])->from(Categories::tableName() . ' AS category');
 }
コード例 #4
0
 public function getCategoriesSelect2()
 {
     $sql = 'SELECT id,name FROM {{%article_categories}} WHERE state = 1';
     $categories = Categories::findBySql($sql)->asArray()->all();
     $array[0] = Yii::t('articles', 'No Parent');
     foreach ($categories as $category) {
         $array[$category['id']] = $category['name'];
     }
     return $array;
 }
コード例 #5
0
 /**
  * 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.');
     }
 }