L
L
lage_442015-02-26 19:57:01
PHP
lage_44, 2015-02-26 19:57:01

Yii2 How to change the search generated by Gii to search all columns through one field?

There is a CRUD application generated through Gii. By default, each column has its own search field. Please tell me what needs to be changed in the search model so that it is possible to search through all columns through one field? Below is the search function generated by gii for the search model.

public function search($params) {

    $query = Clients::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,
      'status' => $this->status,
      'tel_mobile' => $this->tel_mobile,
      'tel_home' => $this->tel_home,
      'age' => $this->age,
      'call_time' => $this->call_time,
      'created_at' => $this->created_at,
    ]);

    $query->andFilterWhere(['like', 'fio', $this->fio])
      ->andFilterWhere(['like', 'address', $this->address])
      ->andFilterWhere(['like', 'comment', $this->comment]);

    return $dataProvider;
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leonid Sysoletin, 2015-02-27
@lage_44

What to add

->orFilterWhere(['like', 'fio', $this->search])
->orFilterWhere(['like', 'address', $this->search])
->orFilterWhere(['like', 'comment', $this->search])

doesn't roll?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question