Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $row = array();
- $query = ContactGroups::find();
- $conditions = ['group_status'=>'ACTIVE'];
- // default data when Insert Process / model are newRecord
- $data = ArrayHelper::map($query->where($conditions)->asArray()->all(),'group_id', 'group_name');
- // data return :
- // [
- // "group_id"=>"group_name",
- // "group_id"=>"group_name",
- // "group_id"=>"group_name",
- // ];
- if (!$model->isNewRecord)
- {
- $conditions = array_merge($conditions,['contact_contact_groups.contact_id'=>$model->contact_id]);
- $dataModel = ArrayHelper::map($query->joinWith('contactContactGroups')->where($conditions)->asArray()->all(),'group_id', 'group_name');
- foreach($dataModel as $k=>$d)
- $row[]=$k;
- }
- ?>
- <div class="form-group field-contacts-group_id">
- <label class="col-sm-2 control-label" for="contacts-group_id">Group</label>
- <div class="col-sm-10">
- <?php
- echo Select2::widget([
- 'name' => 'Contacts[group_id]',
- 'value' => $row, //
- 'data' => $data,
- 'options' => ['placeholder' => 'Select a group ...', 'multiple' => true],
- 'pluginOptions' => [
- 'tags' => true,
- 'maximumInputLength' => 10
- ],
- ]);
- ?>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement