From c0edeca40656654cdc60d8434f5a47b289c304e7 Mon Sep 17 00:00:00 2001 From: b1ek Date: Tue, 20 Aug 2024 14:27:17 +1000 Subject: [PATCH] feat: add list with search --- controllers/ListController.php | 27 +++++++++++++++++++ controllers/SiteController.php | 42 ------------------------------ models/ParameterSearch.php | 47 ++++++++++++++++++++++++++++++++++ views/list/index.php | 26 +++++++++++++++++++ 4 files changed, 100 insertions(+), 42 deletions(-) create mode 100644 controllers/ListController.php create mode 100644 models/ParameterSearch.php create mode 100644 views/list/index.php diff --git a/controllers/ListController.php b/controllers/ListController.php new file mode 100644 index 0000000..e66892c --- /dev/null +++ b/controllers/ListController.php @@ -0,0 +1,27 @@ +search($request->queryParams); + + return $this->render( + 'index', + [ + 'provider' => $dataProvider, + 'searchModel' => $searchModel, + ] + ); + } + +} diff --git a/controllers/SiteController.php b/controllers/SiteController.php index 13e07f3..9ecc13e 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -12,48 +12,6 @@ use app\models\ContactForm; class SiteController extends Controller { - /** - * {@inheritdoc} - */ - public function behaviors() - { - return [ - 'access' => [ - 'class' => AccessControl::class, - 'only' => ['logout'], - 'rules' => [ - [ - 'actions' => ['logout'], - 'allow' => true, - 'roles' => ['@'], - ], - ], - ], - 'verbs' => [ - 'class' => VerbFilter::class, - 'actions' => [ - 'logout' => ['post'], - ], - ], - ]; - } - - /** - * {@inheritdoc} - */ - public function actions() - { - return [ - 'error' => [ - 'class' => 'yii\web\ErrorAction', - ], - 'captcha' => [ - 'class' => 'yii\captcha\CaptchaAction', - 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, - ], - ]; - } - /** * Displays homepage. * diff --git a/models/ParameterSearch.php b/models/ParameterSearch.php new file mode 100644 index 0000000..788bb56 --- /dev/null +++ b/models/ParameterSearch.php @@ -0,0 +1,47 @@ + $query, + ]); + + if (!($this->load($params) && $this->validate())) { + return $dataProvider; + } + + if ($this->title) { + $query->andFilterWhere(['like', 'title', $this->title]); + } + + if ($this->id) { + $query->andFilterWhere(['like', 'id', $this->id]); + } + + return $dataProvider; + } +} \ No newline at end of file diff --git a/views/list/index.php b/views/list/index.php new file mode 100644 index 0000000..cd034dd --- /dev/null +++ b/views/list/index.php @@ -0,0 +1,26 @@ +title = 'params list'; + +?> +

Parameters

+ + '/list/index', + 'method' => 'get', + ]); ?> + + 'btn btn-l btn-success w-100' ]) ?> +

Set your search query in the grid view

+ + + + $provider, + 'filterModel' => $searchModel, +]); ?>