public static function find($id) { $query = DB::connection()->prepare('SELECT * FROM Competitor WHERE id = :id LIMIT 1'); $query->execute(array('id' => $id)); $row = $query->fetch(); if ($row) { return new Competitor(Competitor::get_attributes($row)); } return null; }
private static function get_attributes($row) { $attributes = array(); $attributes['id'] = $row['id']; $attributes['competition_id'] = $row['competitionid']; $attributes['competition_name'] = Competition::find($attributes['competition_id'])->name; $attributes['competitor_id'] = $row['competitorid']; $attributes['competitor_name'] = Competitor::find($attributes['competitor_id'])->name; $attributes['number'] = $row['participantnumber']; $attributes['standing'] = $row['standing']; return $attributes; }
public static function update($id) { self::check_admin_logged_in(); $attributes = self::get_attributes(); $attributes['id'] = $id; $attributes['competition_name'] = Competition::find($attributes['competition_id'])->name; $attributes['competitor_name'] = Competitor::find($attributes['competitor_id'])->name; $attributes['standing'] = Participant::find($id)->standing; $participant = new Participant($attributes); $errors = $participant->validate_number(); if (count($errors) == 0) { $participant->update(); Redirect::to('/competition/' . $participant->competition_id . '/participants', array('message' => 'Kilpailijan numeroa muokattu onnistuneesti!')); } else { self::edit_view(array(Competition::find($participant->competition_id)), array(Competitor::find($participant->competitor_id)), $attributes, $errors); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Competitor the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Competitor::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
echo $form->error($model, 'winner_id'); ?> </div> <?php } ?> <?php if ($this->getAction()->getId() == 'update') { ?> <div class="row"> <?php echo $form->labelEx($model, 'winner_id'); ?> <?php echo $form->dropDownList($model, 'winner_id', Competitor::CompetitorOptions($model->position_id)); ?> <?php echo $form->error($model, 'winner_id'); ?> </div> <?php } ?> <div class="row buttons"> <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?> </div>
public static function destroy($id) { self::check_admin_logged_in(); Competitor::delete($id); Redirect::to('/competitor', array('message' => 'Kilpailija on poistettu onnistuneesti!')); }
/** * 测试动作 */ public function actionTest() { $competitors = Competitor::model()->findByAttributes(array('competitor_id' => '12348045')); echo '<pre>'; print_r($competitors->student->student_name); echo '</pre>'; // Yii::app() ->user -> setFlash('tmp', Yii::app() -> request -> userHostAddress); // $this -> render('test'); }