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
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.