feat: add list with search
This commit is contained in:
parent
97e287e731
commit
c0edeca406
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use app\models\Parameter;
|
||||
use app\models\ParameterSearch;
|
||||
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\web\Request;
|
||||
|
||||
class ListController extends \yii\web\Controller
|
||||
{
|
||||
public function actionIndex(Request $request)
|
||||
{
|
||||
$searchModel = new ParameterSearch();
|
||||
$dataProvider = $searchModel->search($request->queryParams);
|
||||
|
||||
return $this->render(
|
||||
'index',
|
||||
[
|
||||
'provider' => $dataProvider,
|
||||
'searchModel' => $searchModel,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace app\models;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
class ParameterSearch extends Parameter
|
||||
{
|
||||
public $id;
|
||||
public $title;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[[ 'id' ], 'integer' ],
|
||||
[[ 'title' ], 'string' ]
|
||||
];
|
||||
}
|
||||
|
||||
public function scenarios()
|
||||
{
|
||||
return Model::scenarios();
|
||||
}
|
||||
|
||||
public function search($params): ActiveDataProvider
|
||||
{
|
||||
$query = Parameter::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
use yii\helpers\Html;
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
|
||||
$this->title = 'params list';
|
||||
|
||||
?>
|
||||
<h1>Parameters</h1>
|
||||
|
||||
<?php $searchForm = ActiveForm::begin([
|
||||
'action' => '/list/index',
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= Html::submitButton('Run search', [ 'class' => 'btn btn-l btn-success w-100' ]) ?>
|
||||
<p class="small">Set your search query in the grid view</p>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $provider,
|
||||
'filterModel' => $searchModel,
|
||||
]); ?>
|
Loading…
Reference in New Issue