당신이 actionIndex
같은 tipical있는 gridview 관련 행동에 볼 수 dataProvider의
에 대한 gridview에 디스플레이 데이터 당신이하는 dataProvider는 방법) YourmodelSearc (의 새로운 클래스로 usig에게 검색 모델을 구축 것을 볼 수 있습니다
검색()
public function actionIndex()
{
$searchModel = new YourModelSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
및
public function search($params)
{
$query = YourModel::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'your_numeric_col1' => $this->your_col1,
'your_numeric_col2' => $this->your_col2,
......
'id' => $this->id,
]);
$query->andFilterWhere(['like', 'your_string_colx', $this->your_string_colx])
->andFilterWhere(['like', 'your_string_coly', $this->your_string_coly])
.......
->andFilterWhere(['like', 'your_string_coln', $this->your_string_coln]);
return $dataProvider;
}
dataProvider의
에 대한 빌드 dinamically 쿼리에 대한 검색 찾기 contail tipically() 함수와 AndFliter() 함수
그래서 다시 정의하거나 검색을 (조작, 확장) 또는 yii2 필터링 기본적으로는 무엇을하지 않을 때 여러 필터 또는 like
연산자에 대한 쿼리 필터
의 기본 동작을 chainging를 적용) ( 를 새로운 customSeach을 구축 andWhere를 문자열 형식으로 사용해 볼 필요가 있습니다.
andFilterWhere 당신이 null 값 쿼리 건물 코드의 바닥에 대한 간단한 andWhere 테스트를 추가 할 수있는 문자 conditition의 사용을 허용 don'k 사실을
$query->andFilterWhere(['like', 'your_string_colx', $this->your_string_colx])
.......
->andFilterWhere(['like', 'your_string_coln', $this->your_string_coln]);
if (isset($this->your_string_coly)){
$query->andWhere('your_string_coly like concat("%", :param1)',
[':param1'=> $this->your_string_coly])
}
return $query;
나는에 대한 검색을 만들기 위해 무엇을해야하는지 시작 편지의 기초? 의미 검색 텍스트 상자에 "ab"를 입력하면 shouls는 "ab"('ab %'와 같은 mysql의 별칭)으로 시작하는 문자열에 대해 "ab"로 시작하는 항목을 – Goli
으로 제공하고 andFilterWhere의 정상적인 동작으로 충분해야합니다 바이너리 'ab'에 대한 일치를 원한다면 = 필요하고 = – scaisEdge
실제로는 "ab %"가 아닌 "% ab %"를 사용하고 있습니다. 그리고 난 그냥 검색 텍스트 상자에 알파벳순으로 시작하는 문자열에 대한 결과를주고 싶습니다 – Goli