php - yii2 gii crud db relation(one to many) -


gii generated models (with relations) :

/**  * @return \yii\db\activequery  */ public function getclient() {     return $this->hasone(client::classname(), ['id' => 'client_id']); } 

but when generated crud, in client filed input text field. me please, problem?

that's correct. in _form.php file have define dropdown box if user should choose client:

<?= $form->field($model, 'client')->dropdownlist($clients) ?> 

and in controller actions create/update have provide $clients:

return $this->render('create', [  // or: return $this->render('update', [     'model'    => $model,     'clients' => arrayhelper::map(client::find()->all(), 'id', 'name'), ]); 

don't forget pass them in view files create.php , update.php _form.php file:

<?= $this->render('_form', [     'model' => $model,     'clients' => $clients, // <-- added ]) ?> 

in other views want show client may use this:

echo $model->client->name; //or different 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -