public static function getAll() { $options = []; $tags = Tags::find()->all(); if (!empty($tags)) { foreach ($tags as $key => $value) { $options[$value->id] = $value->name; } } return $options; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tags::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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Finds the Tags model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tags the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tags::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getTags() { return $this->hasMany(Tags::className(), ['id' => 'tag_id'])->viaTable('page_tags_rel', ['page_id' => 'id']); }
$data = array('page' => 'Page', 'media' => 'Media'); ?> <label>Page Types</label> <?php echo Select2::widget(['model' => $PageTypeRel_model, 'attribute' => 'page_type', 'data' => $data, 'options' => ['placeholder' => 'Select page Type ...', 'multiple' => true], 'pluginOptions' => ['allowClear' => true]]); ?> </div> <div class="col-md-3"> <label>Tags</label> <?php echo Select2::widget(['model' => $PageTagsRel_model, 'attribute' => 'tag_id', 'data' => Tags::getAll(), 'options' => ['placeholder' => 'Select parent page ...', 'multiple' => true], 'pluginOptions' => ['allowClear' => true]]); ?> </div> </div> </section> </div> <div role="tabpanel" class="tab-pane" id="messages"> <section> <?php