/**
  * Creates a new Career model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($playerID = null)
 {
     $model = new Career();
     if (!isset($playerID)) {
         throw new \yii\web\BadRequestHttpException('Unidentified playerID');
     }
     $player = Player::findOne($playerID);
     if (!isset($player)) {
         throw new \yii\web\BadRequestHttpException('Unidentified player model');
     }
     $model->player_id = $playerID;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (Yii::$app->request->isAjax) {
             $out = ['success' => 'true'];
             return Json::encode($out);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('create', ['model' => $model]);
         }
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Finds the Player model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Player the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Player::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #3
0
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model common\models\Career */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="career-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
$availablePlayers = [];
if (isset($model->player_id)) {
    $player = Player::findOne($model->player_id);
    if (isset($player->id)) {
        $availablePlayers = [$player->id => $player->name];
    }
}
echo $form->field($model, 'player_id')->widget(SelectizeDropDownList::classname(), ['loadUrl' => Url::to(['player/player-list']), 'items' => $availablePlayers, 'options' => ['multiple' => false], 'clientOptions' => ['valueField' => 'value', 'labelField' => 'text', 'persist' => false]]);
?>
 

    <?php 
echo $form->field($model, 'league_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(League::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите лигу...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'season_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Season::find()->orderBy(['id' => SORT_DESC])->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите сезон...'], 'pluginOptions' => ['allowClear' => true]]);
?>
 /**
  * Url: /player/{$id}-{$slug}
  * @param int $id Player id
  * @param $slug
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionPlayer($id, $slug)
 {
     $player = Player::findOne($id);
     if (!isset($player)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     $image = $player->getAsset(Asset::THUMBNAIL_CONTENT);
     $options = ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $player->name, 'columnFirst' => ['post' => ['view' => '@frontend/views/site/team_member', 'data' => compact('player', 'image'), 'weight' => 0]], 'columnSecond' => ['blog_column' => SiteBlock::getBlogPosts(), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]];
     return $this->render('@frontend/views/site/index', $options);
 }