コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = KondisiMotor::find();
     $query->joinWith(['motor0', 'jenisMotor0']);
     //        $query->where('status="belum terjual"');
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['no_totok'] = ['asc' => ['Motor.no_totok' => SORT_ASC], 'desc' => ['Motor.no_totok' => SORT_DESC]];
     $dataProvider->sort->attributes['no_rangka'] = ['asc' => ['Motor.no_rangka' => SORT_ASC], 'desc' => ['Motor.no_rangka' => SORT_DESC]];
     $dataProvider->sort->attributes['no_mesin'] = ['asc' => ['Motor.no_mesin' => SORT_ASC], 'desc' => ['Motor.no_mesin' => SORT_DESC]];
     $dataProvider->sort->attributes['jenisMotor0.nama'] = ['asc' => ['motor.id_jenis' => SORT_ASC], 'desc' => ['motor.id_jenis' => SORT_DESC]];
     $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(['id' => $this->id, 'id_motor' => $this->id_motor, 'no_totok' => $this->no_totok, 'no_rangka' => $this->no_rangka, 'no_mesin' => $this->no_mesin, 'nama' => $this->nama]);
     $query->andFilterWhere(['like', 'kondisi', $this->kondisi])->andFilterWhere(['like', 'keterangan', $this->keterangan]);
     return $dataProvider;
 }
コード例 #2
0
$this->title = 'Kondisi Motor';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="kondisi-motor-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Buat Data Kondisi Motor', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <div class="table-responsive">
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id_motor', 'value' => 'id_motor', 'contentOptions' => ['style' => 'width: 75px;']], ['attribute' => 'jenisMotor0.nama', 'value' => 'motor0.jenisMotor0.nama', 'filter' => Html::activeDropDownList($searchModel, 'nama', \yii\helpers\ArrayHelper::map(\app\models\JenisMotor::find()->select('nama')->distinct()->all(), 'nama', 'nama'), ['class' => 'form-control', 'prompt' => 'Semua'])], ['attribute' => 'no_totok', 'value' => 'motor0.no_totok', 'contentOptions' => ['style' => 'width: 75px;']], ['attribute' => 'no_rangka', 'value' => 'motor0.no_rangka'], ['attribute' => 'no_mesin', 'value' => 'motor0.no_mesin'], ['attribute' => 'kondisi', 'format' => 'raw', 'filter' => Html::activeDropDownList($searchModel, 'kondisi', \yii\helpers\ArrayHelper::map(\app\models\KondisiMotor::find()->select('kondisi')->distinct()->all(), 'kondisi', 'kondisi'), ['class' => 'form-control', 'prompt' => 'Semua']), 'value' => function ($row) {
    $values = ['siap jual' => 'success', 'sedang disiapkan' => 'info', 'belum siap' => 'warning', 'rusak' => 'danger'];
    return Html::tag('span', $row->kondisi, ['class' => 'label label-' . $values[$row->kondisi] . ''], ['style' => 'text-size:14px']);
}], 'keterangan', ['class' => \yii\grid\ActionColumn::className(), 'template' => '{delete} {update}']]]);
?>

    </div>
</div>

コード例 #3
0
 /**
  * Finds the KondisiMotor model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return KondisiMotor the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = KondisiMotor::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }