Yii2 activeDropDownList fundamentals -
i'm new yii2 not mvc (trying move focus ms yii2). i've scaffolded app db using gii. have table called track have table called music_category. there's n:n relationship via link table called track_has_music_category. track model (as scaffolded gii) has function
public function getmusiccategories() { return $this->hasmany(musiccategory::classname(), ['id' => 'music_category_id'])->viatable('track_has_music_category', ['track_id' => 'id']); }
but retrieving categories have been 'link'ed track. guess need like
<?= html::activedropdownlist(thecategorymodel (syntax here??), 'id', arrayhelper::map(thecategorymodel->findall(),'id', ''description)) ?>
well, that. feel though online reference few worked examples.
any appreciated.
cheers mark
let's want attach categories track model ($model):
echo html::activecheckboxlist($model, 'musiccategories', arrayhelper::map(musiccategory::findall(),'id', ''description))
we use activecheckboxlist
here since it's multiple relation. although need add $model logic save these relations. have @ how work many-to-many relations in yii2
Comments
Post a Comment