/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = TrainCategory::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, 'create_time' => $this->create_time, 'update_time' => $this->update_time]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'create_user', $this->create_user])->andFilterWhere(['like', 'update_user', $this->update_user]); return $dataProvider; }
/** * Finds the TrainCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TrainCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TrainCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<div class="train-form"> <?php $form = ActiveForm::begin(['id' => 'addTrain', 'enableAjaxValidation' => false, 'options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'name')->textInput(['style' => 'width:300px']); ?> <?php echo $form->field($model, 'period_num')->dropDownList(\app\models\Train::getPeriodNum(), ['style' => 'width:100px']); ?> <?php echo $form->field($model, 'category')->dropDownList(\app\models\TrainCategory::getAll(), ['style' => 'width:300px']); ?> <?php if (!$model->isNewRecord) { ?> <div class="form-group field-train-category required"> <label for="train-category" class="control-label">培训班次</label> <input type="text" style="width:300px" value="<?php echo $model['code']; ?> " name="Train[name]" disabled class="form-control" id="train-name"> <div class="help-block"></div> </div> <?php } ?>
?> </td> <td> <a href="<?php echo \yii\helpers\Url::to(['/user-center/train-view', 'trainUsersId' => $val['id']]); ?> "><?php echo $val['name']; ?> 第<?php echo $val['period_num']; ?> 期</a> </td> <td><?php echo \app\models\TrainCategory::getNameById($val['category']); ?> </td> <td><?php echo date('Y年m月d日', strtotime($val['begin_time'])); ?> </td> <td><?php echo \app\models\TrainLand::getNameById($val['train_land_id']); ?> </td> <td>招<?php echo $val['recruit_count']; ?> 人 ( <b class="red">已录取 <?php