i need organize multiselect dropdownlist. tried this:
<?= $form->field($model, 'receiver_id')->widget(select2::classname(), [ 'data' => arrayhelper::map(user::find()->all(),'id','username'), 'options' => ['placeholder' => 'select receivers...', 'multiple' => true], 'pluginoptions' => [ 'tags' => true, 'maximuminputlength' => 10 ], ]); ?>
in view seems correctly, in textfield receivers appear 1 one, when press "send" button says receiver id must integer. how can solve issue? need duplicate 1 db record different receivers select using select2 dropdown list. example, choose in dropdownlist user1 , user2, "send" action should work twice accordingly. in db table named 'letter' should 2 same records different id , receiver_id.
my actioncreate function in controller class:
public function actioncreate() { $model = new letter(); if ($model->load(yii::$app->request->post())) { foreach($model->receiver_id $r_id){ $save = new letter(); $save->type_id = $model->type_id; $save->subject = $model->subject; $save->body = $model->body; $save->sender_id = $model->sender_id; $save->start_date = $model->start_date; $save->end_date = $model->end_date; $save->receiver_id = $r_id; $save->save(); } $model->attachment = uploadedfile::getinstance($model, 'attachment'); $filename = pathinfo($model->attachment , pathinfo_filename); $ext = pathinfo($model->attachment , pathinfo_extension); $newfname = $filename.'.'.$ext; $path=yii::getalias('@webroot').'/uploads/'; if(!empty($newfname)){ $model->attachment->saveas($path.$newfname); $model->attachment = $newfname; if($model->save()){ return $this->redirect(['view', 'id' => $model->id]); } } } return $this->render('create', [ 'model' => $model, ]); }
my ide says on "$model->receiver_id" "expected types array or object, actual: int"
thanks in advance.
do receiver_id array on model; ,
foreach($model->receiver_id $r_id){ $save = new yourmodel(); $save->yourproperty = $model->yourproperty; .... $save->receiver_id = $r_id; $save->save(); }
Comments
Post a Comment