2016-10-24 12 views
1

私は 私の$データ変数は、私はそれを保存してい保存値が

<? $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] 

文字列の配列になっている形でkartik複数選択ウィジェット内yii2で複数選択をやろうとしているkartikウィジェットにyii2 multiselected dbを保存する前に保存してIDの文字列として埋め込みますが、私が見たときに私はすべての生徒を選択したものだけでなくすべてを取得しています

私はどのような方法で瞳孔それらは選択され、dbのように名前のように私のビューファイルに表示されます

this is what i'm saving into db (id's of pupils that were chosen)

this is what i'm getting (all the pupils not just chosen ones)

答えて

0

私はので、私はこれを処理する方法を知っていますが、あなたの変数を提供していないし、あなたの方法はどのように見えるか、私はいくつかのランダムなものを書きますので、同じようなことがあります。

のは、あなたが$dataを投棄しているとしましょうとあなたが得る:次に

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

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

これは、新しい行に各変数を出力します:

rotem 
ttt 
tom wininger 
+0

いいけどどこに書きますか? –

+0

ウィジェットにある変数が必要なので –

+0

は文字列として入力します –