dropdownlist examples
dropdown list with template ,use field for using template
in ur user model write getProjectOptions() function
public function getProjectOptions(){
return[
'abc'=>'abc,
'xyz'=>'xyz',
}
now in user controller render this return array
public function actionCreate()
{
$model = new project();
$project=$model->getProjectOptions();
if ($model->load(Yii::$app->request->post())) {
$model->save();
return $this->redirect(['view', 'id' => $model->name]);
} else {
return $this->render('create', // u can write _form directly or u can render to create then _form
[
'model' => $model,
'project'=>$project,
]);
}
}
In view part
<?= $form->field($model, ‘user’)->dropDownList($project, [‘prompt’=>’’]); ?>
if you want to check record is already exists in database just add below rule in model rules function
[[‘attribute_name’],‘unique’],
if you want to set your own error message then use below
[['attribute_name'],'unique',message=>'your message],
disable any field in update form
if u want to disable a field and restrict to user for edit the field
<?= $form->field($model, ‘abbr’)->textInput([‘readonly’ => !$model->isNewRecord]) ?>