Answer the question
In order to leave comments, you need to log in
How to select checkbox when changing data Yii2?
There is a form
<?=$f->field($flora_user, 'user_id')->checkBoxList(ArrayHelper::map($user,'id','fio'))->label('Автор(ы):')?>
$floraUser = new floraUser();
$user = User::find()->all();
$floraUser = $this->findModel($id)->users;
findModel($id)
{
if (($model = Flora::findOne($id)) !== null) {
return $model;
}
public function getFloraUsers()
{
return $this->hasMany(FloraUser::className(), ['flora_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUsers()
{
return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('flora_user', ['flora_id' => 'id']);
}
Answer the question
In order to leave comments, you need to log in
exec will just execute the query, use getAll/getRow/getCol/getCell/getAssoc to get the results.
<?= $f->field($flora, 'users')
->checkBoxList(User::find()->select(['name', 'id'])->indexBy('id')->column())
->label('Автор(ы):') ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question