2017-09-12 85 views
0

我安裝了yii2出口menu.it工作正常,但搜索不能正常工作。我不明白什麼是錯誤的?請幫忙解決它...... 這裏是代碼 -搜索不工作,在yii2 gridview

<?php 
     $gridColumns = [ 
     [ 
     'class' => 'yii\grid\SerialColumn', 
     ], 
     'name', 
     'company_mail',  
     'created', 
     'modified', 
     'modified_by_id', 
     ['class' => 'yii\grid\ActionColumn', 'urlCreator'=>function(){return '#';}], 

    ]; ?> 

<?php 
echo ExportMenu::widget([ 
'dataProvider' => $dataProvider, 
'filterModel'=>$searchModel, 
'columns' => $gridColumns, 
'target' => ExportMenu::TARGET_BLANK, 
    ]); 

?> 
<?php 
echo GridView::widget([ 
'dataProvider' => $dataProvider, 
'filterModel' => $searchModel, 
'columns' => $gridColumns, 
]); 
?> 

回答

0

在companiesController.php, $數據提供程序= $ searchModel->搜索(警予:: $ APP->請求 - > queryParams); 這條線被錯誤地評論了。

感謝所有幫助和響應..

0

添加到下面的函數搜索模式

public function search($params) 
    { 
     $query = YourModel::find(); 

     $dataProvider = new ActiveDataProvider([ 
      'query' => $query, 
      'sort' => [ 
       'defaultOrder' => [ 

       ] 
      ], 
     ]); 

     $this->load($params); 

     if (!$this->validate()) { 
      // uncomment the following line if you do not want to return any records when validation fails 
      // $query->where('0=1'); 
      return $dataProvider; 
     } 


     $query->andFilterWhere(['like', 'name', $this->name]) 
      ->andFilterWhere(['like', 'company_mail', $this->company_mail]) 
      ->andFilterWhere(['like', 'modified', $this->modified]) 
      ->andFilterWhere(['like', 'created', $this->created]) 
      ->andFilterWhere(['like', 'modified_by_id', $this->modified_by_id]); 

     return $dataProvider; 
    } 
+0

感謝...但它不工作...此代碼是在我的項目已經存在.. ....請建議別的 – Darsh