/** * Displays a single Users model. * @param integer $id * @return mixed */ public function actionView($id) { $modelInfo = UsersInfo::findOne(['user_id' => $id]); $modelEducation = UsersEducation::findAll(['user_id' => $id]); $modelTrain = UsersTrain::findAll(['user_id' => $id]); $modelVocational = UsersVocational::findAll(['user_id' => $id]); $modelPlayers = UsersPlayers::findAll(['user_id' => $id]); return $this->render('view', ['model' => $this->findModel($id), 'modelInfo' => $modelInfo, 'modelEducation' => $modelEducation, 'modelTrain' => $modelTrain, 'modelVocational' => $modelVocational, 'modelPlayers' => $modelPlayers]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UsersPlayers::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, 'user_id' => $this->user_id, 'begin_time' => $this->begin_time, 'end_time' => $this->end_time, 'level' => $this->level, 'create_time' => $this->create_time, 'update_time' => $this->update_time]); $query->andFilterWhere(['like', 'team', $this->team])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'witness', $this->witness])->andFilterWhere(['like', 'witness_phone', $this->witness_phone])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'update_user', $this->update_user]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getUsersPlayers() { return $this->hasMany(UsersPlayers::className(), ['user_id' => 'id']); }
public function actionRegisterPlayers() { if (Yii::$app->request->isPost) { $infoParams = Yii::$app->request->post(); $userId = Yii::$app->user->id; $trainId = Yii::$app->request->post('train_id'); $modelInfo = new UsersPlayers(); $infoParams['UsersPlayers']['user_id'] = $userId; if (empty($infoParams['UsersPlayers']['end_time'])) { $infoParams['UsersPlayers']['end_time'] = date('Y-m-d H:i:s', time()); } $infoInfo = $infoParams; if ($modelInfo->load($infoInfo) && $modelInfo->save()) { return $this->redirect(['/user/register-players', 'train_id' => $trainId]); } else { throw new ServerErrorHttpException('系统错误,原因:' . json_encode($modelInfo->errors, JSON_UNESCAPED_UNICODE)); } } elseif (Yii::$app->request->get('id')) { if (UsersPlayers::deleteAll(['id' => Yii::$app->request->get('id')])) { return $this->redirect(['/user/register-players', 'train_id' => Yii::$app->request->get('train_id')]); } else { throw new ServerErrorHttpException('系统错误,原因:删除失败!'); } } else { $userId = Yii::$app->user->id; $model = UsersPlayers::findAll(['user_id' => $userId]); $trainId = Yii::$app->request->get('train_id'); $trainName = Train::getOneTrainNameById($trainId); return $this->render('register-players', ['model' => $model, 'train_id' => $trainId, 'trainName' => $trainName]); } }
public function actionUserPlayers() { if (Yii::$app->request->isPost) { $infoParams = Yii::$app->request->post(); $infoParams['UsersPlayers']['user_id'] = Yii::$app->user->id; if (empty($infoParams['UsersPlayers']['end_time'])) { $infoParams['UsersPlayers']['end_time'] = date('Y-m-d H:i:s', time()); } $infoInfo = $infoParams; $model = new UsersPlayers(); if ($model->load($infoInfo) && $model->save()) { return $this->redirect('/user-center/user-info'); } else { throw new ServerErrorHttpException('系统错误,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE)); } } else { if (Yii::$app->request->get('id')) { UsersPlayers::findOne(Yii::$app->request->get('id'))->delete(); return $this->redirect('/user-center/user-info'); } else { $model = UsersPlayers::findAll(['user_id' => Yii::$app->user->id]); $levelName = Level::getOneLevelNameById(Yii::$app->user->identity->level_id); $photo = UsersInfo::getPhotoByUserId(\Yii::$app->user->id); $messageCount = MessagesUsers::getCountByUserIdAndType(\Yii::$app->user->id); $currentTrain = TrainUsers::getTrainByUserId(Yii::$app->user->id); $data = ['levelName' => $levelName, 'currentTrain' => $currentTrain, 'photo' => $photo, 'messageCount' => $messageCount]; return $this->render('user-players', ['data' => $data, 'model' => $model]); } } }
/** * Finds the UsersPlayers model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UsersPlayers the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UsersPlayers::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<tr> <td></td> <td><input type="submit" value="保 存" class="fixe_btn btnBoxset"/></td> </tr> </table> <?php ActiveForm::end(); ?> <p class="go_add"><a href="javascript:;">继续添加</a></p> </div> </div> </li> <li> <h1><span>运动经历</span>已完善(<?php echo \app\models\UsersPlayers::getCountByUserId(Yii::$app->user->id); ?> 条)</h1> <div style="display:none;" class="form_input"> <div class="divp_pt"> <table cellpadding="0" cellspacing="0" class="wans_content"> <tr> <th>序</th> <th>效力球队</th> <th>时间</th> <th>任职</th> <th>操作</th> </tr> <?php if (!empty($userPlayers)) {