/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Coach::find();
     $country = new Country();
     $coachTable = Coach::tableName();
     $countryTable = Country::tableName();
     $query->joinWith(['country' => function ($query) use($countryTable) {
         $query->from(['country' => $countryTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     // enable sorting for the related columns
     $addSortAttributes = ["country.name"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(["{$coachTable}.id" => $this->id, 'birthday' => $this->birthday, 'country_id' => $this->country_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', "{$coachTable}.name", $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'position', $this->position])->andFilterWhere(['like', 'notes', $this->notes])->andFilterWhere(['like', 'player_carrer', $this->player_carrer])->andFilterWhere(['like', 'coach_carrer', $this->coach_carrer])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'country.name', $this->getAttribute('country.name')]);
     return $dataProvider;
 }
Exemple #2
0
<div class="team-coach-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'team_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Team::find()->where(['id' => Team::getTeamsConstants()])->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите команду...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'season_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Season::find()->where(['window' => Season::WINDOW_WINTER])->orderBy(['name' => SORT_DESC])->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите сезон...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'coach_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Coach::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите тренера...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
// $availableCoaches = [];
// $coach = $model->coach;
// if(isset($coach->id)) {
//     $availableCoaches = [$coach->id => $coach->name];
// }
// echo $form->field($model, 'coach_id')->widget(SelectizeDropDownList::classname(), [
//     'loadUrl' => Url::to(['coach/coach-list']),
//     'items' => $availableCoaches,
//     'options' => [
//         'multiple' => false,
//         'placeholder' => 'Выберите тренера...',
//     ],