Answer the question
In order to leave comments, you need to log in
How to work with MultipleLoad and MultipleValidate correctly?
Here is the model
class PhoneForm extends Model
{
public $value;
public $type;
public function rules()
{
return [
['value', 'required'],
['type', 'integer'],
['value', 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'type' => 'Тип',
'value' => 'Значение',
];
}
}
This is how it is implemented in the form<?php foreach ($model->phones as $key => $phone): ?>
<div class="row">
<div class="col-md-6">
<?= $form->field($phone, "[$key]type")->dropDownList($phone->typeArr)->label(false) ?>
</div>
<div class="col-md-6">
<?= $form->field($phone, "[$key]value")->textInput(['maxlength' => true, 'placeholder' => 'Номер'])->label(false) ?>
</div>
</div>
<?php endforeach ?>
class PhoneService
{
public $form;
public $user_id;
public function __construct(int $id)
{
$this->form=new PhoneForm();
$this->user_id=$id;
}
public function create(array $phones){
if(Model::loadMultiple($this->form,$phones)&& Model::validateMultiple($this->form)){
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question