I am integrating yii2-formwizard for tabular input but unable to submit the data to my controller action and use Model::loadMultiple.
I have to declare my model as array and then I need to initialize it before passing to view and in buttflattery/yii2-formwizard front-end I must specify my model as array fine but I can not retrieve data from my controller dynamically.
I need to dynamically create instance from front-end and save them in back end. I can save only the instance I have initialize from my controller.if I do not initialize only first one instance saved.and also when I initialize multiple instance using for loop, front end replicate for all instance at once which again I do not need.
//controller
public function actionCreatemulti()
{
$this->layout='layout2';
$education = [new Edusubject()];
//## initialize array for 2 element (if I not initialize only one object pass or saved)
for ($i=0; $i < 2 ; $i++) {
$education[]= new Edusubject();
}
//## Model::loadMultiple --> works only if $education is declared as array
if (Model::loadMultiple($education, Yii::$app->request->post()) && Model::validateMultiple($education)) {
foreach ($education as $edu) {
$edu->save(false);
}
return $this->render('dummy');
}
return $this->render('createmulti', [
'education' => $education,
]);
}
FormWizard code in my View
<?php
echo FormWizard::widget(
[
'formOptions' => [
'id' => 'my_form_tabular'
],
'steps' => [
[
//should be a single model or array of Activerecord model objects but for a single model only see wiki on github
'model' => $education, //## here I canot declared array again as I pass an array alredy from controller
//set step type to tabular
'type' => FormWizard::STEP_TYPE_TABULAR,
when i declare model as array in my view i can get dynamic form as described in wiki but I can not save this array since I can not implement yii2 Collecting tabular input as described, on the other hand if I declare model as array and initialize it and send to front end then form is not dynamic. it is shown all instance in form so I need not press "add" button, which I do not need.