yii2中的选定值

yii2中的选定值,yii2,Yii2,我试图为每个国家添加运输成本。每当我试图保存这些值时,它会在表中添加多行。 但是我如何在yii2的编辑表单中显示所有这些选定的值呢 控制器: $countrywiseshipping = new ProductCountrywiseshipping(); $countryArr = []; foreach ($countrylist as $country) { $countryArr[$country->idCountry->id_country]

我试图为每个国家添加运输成本。每当我试图保存这些值时,它会在表中添加多行。 但是我如何在yii2的编辑表单中显示所有这些选定的值呢

控制器:

 $countrywiseshipping = new ProductCountrywiseshipping();

  $countryArr = [];
    foreach ($countrylist as $country) {

        $countryArr[$country->idCountry->id_country]['code'] = $country->idCountry->iso_code;
        $countryArr[$country->idCountry->id_country]['call_prefix'] = $country->idCountry->call_prefix;
        $countryArr[$country->idCountry->id_country]['name'] = $country->name;
    } 
视图:

如果我打印变量$countrywiseshipping,它将返回所有选定的值。
但我希望所有选定的国家和价格在编辑形式。怎么可能?

请定义“选定”的含义?下拉字段中是否有未选择的选项?请添加您的更新操作和视图代码,或澄清用于更新过程的给定视图和控制器代码?如何在下拉列表(国家/地区)和文本框(成本)中显示保存的记录?
   <div class="col-sm-7 col-md-8 col-xs-6" id="cntryDiv">
   <div class="row repeat-addcountry-part" id="subcntry1">
    <div class="col-sm-3" id="shipcountry">
        <label>Country</label>
            <div class="categry-select">    
                <div class="styled-select">                                                         
                <select class="countries2 form-control" data-country="US">
                    <?php foreach ($countryArr as $country_id => $country) {     ?>
                            <option id="country_<?php echo $country_id ?>" value="<?php echo $country_id ?>" data-code="<?php echo strtolower($country['code']) ?>" data-prefix="<?php echo $country['call_prefix'] ?>" data-image="images/blank.gif" data-imagecss="flag <?php echo strtolower($country['code']) ?>" data-title="<?php echo $country['name'] ?>"><?php echo $country['name'] ?></option>
                        <?php } ?>
                </select>
                </div>                                                      
            </div>                                                      
        </div>
        <div class="col-sm-3" id="costs">
        <label>Cost</label>
        <div class="input-cost">
            <?php echo $form->field($countrywiseshipping, 'price[]')->textInput(['onblur'=>'assocC(this)'])->label(false) ?>                                                    
        </div>                                                      
        </div>
        <div class="col-sm-3">
        <a href="#" class="del-contry-btn rmv-cntry">Del Country</a>
        </div>
        <label>(To offer free shipping to your customers just enter $0.00.)</label>                                                 
        </div>                                          
    </div>
  $countrywiseshipping = ProductCountrywiseshipping::find()->where(['id_product' => $id_product])->all();