我要添加過濾器與列表視圖(有些事情喜歡在網格視圖),但我不不知道如何像網格視圖添加過濾器搜索列表視圖Yii2
過濾器我想是的CheckBox如何做和DropDown選項。
這是我的操作代碼在SiteController
<?php
public function actionMobiles(){
$searchModel = new MobileSearch();
//$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
//$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider = new ActiveDataProvider([
'query' => Mobile::find(),
'pagination' => [
'pageSize' => 1,
],
]);
// get the posts in the current page
//$posts = $dataProvider->getModels();
return $this->render('mobiles', ['dataProvider' => $dataProvider,'searchModel' => $searchModel]);
}
?>
在查看文件我有2個文件:
這裏是手機瀏覽:
<?php
use yii\widgets\ListView;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper ;
use app\models\Mobile;
?>
<?= ListView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'itemView' => '_mobiles',
]); ?>
並在_mobiles我有:
<?php
use yii\widgets\DetailView;
?>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
//'id',
'id',
'title',
//'ativo',
],
]) ?>
它正確地顯示數據庫中的數據以及它的分頁。 但如何添加篩選器更新列表(CheckBox和DropDown列表用於更新)?
加 'filterModel'=> $ searchModel,在你的列表視圖控件 – Gunnrryy
??? @Gunnrryy – areff
設置未知屬性:yii \ widgets \ ListView :: filterModel @Gunnrryy – areff