<?php use app\models\TeamWork; use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model app\models\Project */ /* @var $form yii\widgets\ActiveForm */ $teamWorkItems = ArrayHelper::map(TeamWork::find()->all(), function (TeamWork $teamWork) { return $teamWork->id; }, function (TeamWork $teamWork) { return $teamWork->name; }); ?> <div class="project-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'team_work_id')->dropDownList($teamWorkItems); ?> <?php
/** * Finds the TeamWork model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TeamWork the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TeamWork::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getTeamWork() { return $this->hasOne(TeamWork::className(), ['id' => 'team_work_id']); }