## 模型类modules(CountrySearch -> search())
public function search($params)
{
$query = Country::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 2, //每页显示条数
],
]);
$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;
}
// grid filtering conditions
$query->andFilterWhere([
'population' => $this->population,
]);
$query->andFilterWhere(['like', 'code', $this->code])
->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
###控制器类controllers ->Index()
namespace app\controllers;
use Yii;
use app\models\Country;
use app\models\CountrySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
public function actionIndex()
{
$searchModel = new CountrySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
//echo "<pre/>";
//var_dump($dataProvider['countries']);
//exit();
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
###视图views(country->index)
## 模型类modules(CountrySearch -&gt; search())public function search($params){ $query = Country::find(); // add conditions that should always apply here $dataProvider = new ActiveDataPr...