namespace app\controllers;
use yii_app\records\Products1cNomenclature;
-use yii\data\ActiveDataProvider;
+use yii_app\records\Products1cNomenclatureSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
*/
public function actionIndex()
{
- $dataProvider = new ActiveDataProvider([
- 'query' => Products1cNomenclature::find(),
- /*
- 'pagination' => [
- 'pageSize' => 50
- ],
- 'sort' => [
- 'defaultOrder' => [
- 'id' => SORT_DESC,
- ]
- ],
- */
- ]);
+ $searchModel = new Products1cNomenclatureSearch();
+ $dataProvider = $searchModel->search($this->request->queryParams);
return $this->render('index', [
+ 'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Products1cNomenclature model.
- * @param string $id GUID - уникальный номер номенклатуры в 1С
+ * @param string $id GUID
* @return string
* @throws NotFoundHttpException if the model cannot be found
*/
/**
* Updates an existing Products1cNomenclature model.
* If update is successful, the browser will be redirected to the 'view' page.
- * @param string $id GUID - уникальный номер номенклатуры в 1С
+ * @param string $id GUID
* @return string|\yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
/**
* Deletes an existing Products1cNomenclature model.
* If deletion is successful, the browser will be redirected to the 'index' page.
- * @param string $id GUID - уникальный номер номенклатуры в 1С
+ * @param string $id GUID
* @return \yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
/**
* Finds the Products1cNomenclature model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
- * @param string $id GUID - уникальный номер номенклатуры в 1С
+ * @param string $id GUID
* @return Products1cNomenclature the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
--- /dev/null
+<?php
+
+namespace yii_app\records;
+
+use yii\base\Model;
+use yii\data\ActiveDataProvider;
+use yii_app\records\Products1cNomenclature;
+
+/**
+ * Products1cNomenclatureSearch represents the model behind the search form of `yii_app\records\Products1cNomenclature`.
+ */
+class Products1cNomenclatureSearch extends Products1cNomenclature
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function rules()
+ {
+ return [
+ [['id', 'location', 'name', 'type_num', 'category', 'subcategory', 'species', 'sort', 'measure', 'color', 'type'], 'safe'],
+ [['size'], 'integer'],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function scenarios()
+ {
+ // bypass scenarios() implementation in the parent class
+ return Model::scenarios();
+ }
+
+ /**
+ * Creates data provider instance with search query applied
+ *
+ * @param array $params
+ *
+ * @return ActiveDataProvider
+ */
+ public function search($params)
+ {
+ $query = Products1cNomenclature::find();
+
+ // add conditions that should always apply here
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => $query,
+ ]);
+
+ $this->load($params);
+
+ if (!$this->validate()) {
+ // uncomment the following line if you do not want to return any records when validation fails
+ // $query->where('0=1');
+ return $dataProvider;
+ }
+
+ // grid filtering conditions
+ $query->andFilterWhere([
+ 'size' => $this->size,
+ ]);
+
+ $query->andFilterWhere(['ilike', 'id', $this->id])
+ ->andFilterWhere(['ilike', 'location', $this->location])
+ ->andFilterWhere(['ilike', 'name', $this->name])
+ ->andFilterWhere(['ilike', 'type_num', $this->type_num])
+ ->andFilterWhere(['ilike', 'category', $this->category])
+ ->andFilterWhere(['ilike', 'subcategory', $this->subcategory])
+ ->andFilterWhere(['ilike', 'species', $this->species])
+ ->andFilterWhere(['ilike', 'sort', $this->sort])
+ ->andFilterWhere(['ilike', 'measure', $this->measure])
+ ->andFilterWhere(['ilike', 'color', $this->color])
+ ->andFilterWhere(['ilike', 'type', $this->type]);
+
+ return $dataProvider;
+ }
+}
<?php
+use kartik\grid\ActionColumn;
+use kartik\grid\GridView;
use yii_app\records\Products1cNomenclature;
use yii\helpers\Html;
use yii\helpers\Url;
-use yii\grid\ActionColumn;
-use yii\grid\GridView;
/** @var yii\web\View $this */
+/** @var yii_app\records\Products1cNomenclatureSearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
-$this->title = 'Товары с категориями';
+$this->title = 'Products1c Nomenclatures';
$this->params['breadcrumbs'][] = $this->title;
?>
-<div class="products1c-nomenclature-index p-4">
+<div class="products1c-nomenclature-index">
<h1><?= Html::encode($this->title) ?></h1>
-
<?= GridView::widget([
'dataProvider' => $dataProvider,
- 'columns' => [
- ['class' => 'yii\grid\SerialColumn'],
+ 'filterModel' => $searchModel,
+ 'columns' => [
+ ['class' => 'kartik\grid\SerialColumn'],
'id',
'location',
'name',
'color',
[
'class' => ActionColumn::class,
+
'template' => '{view}',
'urlCreator' => function ($action, Products1cNomenclature $model, $key, $index, $column) {
return Url::toRoute([$action, 'id' => $model->id]);
}
],
],
- ]); ?>
+ ]); ?>
</div>
+
+