简体   繁体   中英

Save multiselected values yii2 in kartik widget

I'm trying to do multiselect with kartik multiselect widget in yii2 in the form my $data variable is getting an array of strings

<? $data = ArrayHelper::map(pupil::find()->all(),'pupilId','firstname'); ?>
 var_dump($data) = array(6) { [1]=> string(5) "rotem" [3]=> string(3) "ttt" [6]=> string(12) "tom wininger" [7]

i'm saving it to db by before save method and implode as string of id's but when i'm trying to see it in my view i'm getting all the pupils not just the chosen one

what method can i write that will take only the pupils the were chosen and will show it in my view file like in db but as names

这是我保存到db(被选中的学生的id)

这就是我得到的(所有的学生不仅仅是选择的)

I have similar thing so I know how to handle this but since you haven't provided your variables and how your method looks like, I'll write some random one.

Let's say, you're dumping $data and you get:

array(3) {
    [1]=> string(5) "rotem"
    [3]=> string(3) "ttt"
    [6]=> string(12) "tom wininger"
}

Then:

foreach($data as $dat) {
    // Do your operators here, for example:
    echo $dat.'<br>';
}

This will print each variable in a new line:

rotem
ttt
tom wininger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM