/** * @return array */ public function getCategories() { $models = WorkCategory::find()->asArray()->all(); return ArrayHelper::map($models, 'id', 'title'); }
/** * Lists all WorkCategory models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => WorkCategory::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
<div class="work-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php if (Yii::$app->user->can('editWork')) { ?> <?php echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(\app\models\Participant::find()->asArray()->all(), 'user_id', 'name')); ?> <?php } ?> <?php echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\app\models\WorkCategory::find()->asArray()->all(), 'id', 'title'), ['onchange' => ' $.post( "' . Yii::$app->urlManager->createUrl('work/get-file-info?id=') . '"+$(this).val(), function( data ) { $( "#fileInfoHint" ).html( data ); }); ']); ?> <?php echo $form->field($model, 'file')->fileInput()->hint($this->context->actionGetFileInfo($model->category_id), ['id' => 'fileInfoHint']); ?> <?php echo $form->field($model, 'title')->textInput(); ?> <?php