/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Specifications::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'type' => $this->type, 'available' => $this->available]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'items', $this->items]);
     return $dataProvider;
 }
 /**
  * Finds the Specifications model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Specifications the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Specifications::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#3
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\models\goods\SpecificationsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $specModel common\models\goods\Specifications */
$this->title = Yii::t('Goods', 'Specifications');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="specifications-index">

    <p>
        <?php 
echo Html::a(Yii::t('Goods', 'Create Specifications'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'tableOptions' => ['class' => 'table table-striped table-bordered text-center'], 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'headerOptions' => ['class' => 'text-center', 'width' => '5%']], ['attribute' => 'name', 'headerOptions' => ['class' => 'text-center', 'width' => '25%']], ['attribute' => 'parent_id', 'format' => 'raw', 'value' => function ($data) {
    return \common\models\goods\Specifications::specGroup()[$data->parent_id];
}, 'headerOptions' => ['class' => 'text-center', 'width' => '35%']], ['attribute' => 'type', 'format' => 'raw', 'value' => function ($data) {
    return \common\models\goods\Specifications::specTypes()[$data->type];
}, 'filter' => Html::activeDropDownList($searchModel, 'type', \common\models\goods\Specifications::specTypes(), ['class' => 'form-control', 'prompt' => Yii::t('System', 'common_whole')]), 'headerOptions' => ['class' => 'text-center', 'width' => '15%']], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>