/** * Finds the Sport model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Sport the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Sport::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return array */ public static function getKindsOfSport() { $result = []; foreach (Sport::find()->asArray()->all() as $item) { $result[$item['id']] = $item['name']; } return $result; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Sport::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['or', ['like', 'name', $this->name], ['like', 'url_key', $this->url_key]]); return $dataProvider; }
public function up() { /* @var Sport $weightlifting */ $weightlifting = Sport::findOne(1); $weightlifting->style = 'blue-madison'; $weightlifting->icon = 'icon-weightlifting ml-0'; $weightlifting->save(); /* @var Sport $powerlifting */ $powerlifting = Sport::findOne(2); $powerlifting->style = 'red-intense'; $powerlifting->icon = 'icon-powerlifting'; $powerlifting->save(); /* @var Sport $kettlebell */ $kettlebell = Sport::findOne(3); $kettlebell->style = 'green-haze'; $kettlebell->icon = 'icon-kettlebell ml-0'; $kettlebell->save(); }
/* @var $model common\models\Competition */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="competition-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'sport_id')->dropDownList(ArrayHelper::map(Sport::find()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'events_set_id')->dropDownList(ArrayHelper::map(EventsSet::find()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'date_start')->widget(DatePicker::classname(), ['dateFormat' => 'yyyy-MM-dd']); ?> <?php echo $form->field($model, 'date_finish')->widget(DatePicker::classname(), ['dateFormat' => 'yyyy-MM-dd']); ?> <?php
/** * Finds the Sport model based on its url_key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $url_key * @return Sport the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findSportModel($url_key) { if (($model = Sport::findOne(['url_key' => $url_key])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getSport() { return $this->hasOne(Sport::className(), ['id' => 'sport_id'])->inverseOf('eventsSets'); }
/** * @return \yii\db\ActiveQuery */ public function getSport() { return $this->hasOne(Sport::className(), ['id' => 'sport_id']); }
<?php use yii\helpers\Html; use yii\widgets\DetailView; /* @var $this yii\web\View */ /* @var $model common\models\Competition */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Competitions'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="competition-view"> <p> <?php echo Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'name', ['label' => $model->getAttributeLabel('sport_id'), 'value' => \common\models\Sport::findOne($model->sport_id)->name], ['label' => $model->getAttributeLabel('events_set_id'), 'value' => \common\models\EventsSet::findOne($model->events_set_id)->name], 'date_start', 'date_finish', 'location', 'created_at:datetime', 'updated_at:datetime']]); ?> </div>