/**
  * 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.');
     }
 }
 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();
 }
 /**
  * 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.');
     }
 }
Пример #4
0
<?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>