Skip to content

Instantly share code, notes, and snippets.

@nadar
Last active July 30, 2019 09:57
Show Gist options
  • Save nadar/d281c6f004f2d52214ae5521fdd401a7 to your computer and use it in GitHub Desktop.
Save nadar/d281c6f004f2d52214ae5521fdd401a7 to your computer and use it in GitHub Desktop.
activedataprovider.php
<?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