我正在尝试为每个国家/地区添加运费。每当我尝试保存所有值时,它会在表格中添加多行。 但是如何在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;
}
查看:
<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();
如果我打印变量$ countrywiseshipping,它将返回所有选定的值。 但我希望所有选定的国家/地区以及编辑形式的价格。怎么可能?