Last active
July 30, 2019 09:57
-
-
Save nadar/d281c6f004f2d52214ae5521fdd401a7 to your computer and use it in GitHub Desktop.
activedataprovider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SearchModel extends \yii\base\Model | |
{ | |
public $suchen; | |
public function rules() | |
{ | |
return [['suchen'], 'string']; | |
} | |
public function applyQuery(Query $query) | |
{ | |
if ($this->suchen) { | |
$query->andWhere(['like', 'content', $this->suchen]); | |
} | |
} | |
} | |
class Controller { | |
public function actionIndex() | |
{ | |
$query = FileLogModel::find(); | |
$searchModel = new SearchModel(); | |
if ($searchModel->load(Yii::$app->request->get()) { | |
$searchModel->applyQuery($query); | |
} | |
$logProvider = new ActiveDataProvider([ | |
'query' => $query, | |
]); | |
return $this->render('index', [ | |
'logProvider' => $logProvider, | |
'searchModel' => $searchModel, | |
]); | |
} | |
} | |
// view fiel: | |
echo GridView::widget([ | |
'dataProvider' => $logProvider, | |
'searchModel' => $searchModel, | |
'columns' => [ | |
[ | |
'attribute' => 'name', | |
'filter' => Html::activeIinput($searchModel, 'subscription'), | |
] | |
], | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment