Нашел в интернет решение, но в одном месте не могу допетрить!!!
Выводит и хранит данные правильно, а вот как записать Ж(
Код: Выделить всё
public function setRealEstateService($tagsId)
{
$this->realEstateService = (array) $tagsId; //не понятно откуда tagsId правильно сформировать...
}
public function afterSave($insert, $changedAttributes)
{
Servicelinks::deleteAll(['rs_id' => $this->id]);
$values = [];
foreach ($this->realEstateService as $id) {
$values[] = [$this->id, $id];
}
self::getDb()->createCommand()
->batchInsert(Servicelinks::tableName(), ['rs_id', 'sr_id'], $values)->execute();
parent::afterSave($insert, $changedAttributes);
}
никак не могу понять как правильно на форме это оформить если я использую расширение Kartik/select2
Код: Выделить всё
$data = ArrayHelper::map(Service::find()->asArray()->all(), 'id', 'service');
echo '<label class="control-label">Tag Multiple</label>';
echo Select2::widget([
'name' => 'tagsId',
'model' => $model->tagsId,
'value' => $model->getService(), // initial value
'data' => $data,
'options' => ['placeholder' => 'Select a color ...', 'multiple' => true],
'pluginOptions' => [
'tags' => true,
'multiple' => true,
'maximumInputLength' => 10,
],
]);
вот тут не понятно...
$this->realEstateService = (array) $tagsId; //не понятно откуда tagsId правильно сформировать...