Answer the question
In order to leave comments, you need to log in
How to make multi-nested table entry in Yii in create?
Help please with a problem. Can not decide. More precisely decided on half.
I need to make a block with steps and sub-steps.
Here is how it all looks in view.
It is clear that there can be many stages with points, and there can also be an unlimited number of sub-stages in them.
The problem is that in the creation, only stages are created. I figured it out with them, but the stages do not want to be loaded into the model.
here is the code of view stages and sub-stages
<?= \unclead\multipleinput\TabularInput::widget([
'models'=>$model,
'addButtonPosition'=>\unclead\multipleinput\MultipleInput::POS_FOOTER,
'rendererClass' => \unclead\multipleinput\renderers\ListRenderer::className(),
'addButtonOptions'=>['class'=>'ag_2_1', 'label'=>'Добавить этап'],
'layoutConfig'=>['offsetClass'=>'','labelClass'=>'','wrapperClass'=>'', 'errorClass'=>''],
'columns' => [
[
'name'=>'title',
'options'=>[
'class'=>'input_goal'
]
],
[
'name'=>'description',
'type'=>'textarea',
'options'=>[
'class'=>'input_goal'
]
],
[
'name'=>'date_finish_stage',
'type'=>\kartik\date\DatePicker::className(),
'options'=>[
]
],
[
'name'=>'Substages',
'type'=>\unclead\multipleinput\MultipleInput::className(),
'options'=>[
'columns'=>[
[
'name'=>'text',
'type'=>\unclead\multipleinput\MultipleInputColumn::TYPE_TEXT_INPUT
]
]
]
],
]
])
?>
public function actionCreate()
{
$model = new Goals;
$Stages = [new Stage()];
$criterias = CriteriesGoals::find()->all();
$Substages = ;
if ($model->load(Yii::$app->request->post())) {
$model->id_user = Yii::$app->user->id;
$model->status = self::ACTIVEGOAL;
$model->doc = UploadedFile::getInstance($model, 'doc');
if ($model->doc) {
if($model->upload())
{
$model->doc = $model->doc->name;
}
}
$Substages[] = new Substage;
Model::loadMultiple($Substages, Yii::$app->request->post('Stage'));
print_r(Yii::$app->request->post('Stage'));
die();
if($model->save())
{
$items = Yii::$app->request->post('Stage',[]);
for($i = 0; $i<count($items); $i++){
$Stages[$i] = new Stage();
}
if(Model::loadMultiple($Stages, Yii::$app->request->post()) && Model::validateMultiple($Stages))
{
foreach ($Stages as $key=>$Stage) {
$Stage->id_user = Yii::$app->user->id;
$Stage->goal_id = $model->id;
$Stage->save(false);
/*$Substages[$key] = new Substage();
Model::loadMultiple($Substages, Yii::$app->request->post('Stage')['Stage'][$key],'Substages');
foreach($Substages as $key2=>$substage){
//$substage->text = Yii::$app->user->id;
$substage->id_user = Yii::$app->user->id;
$substage->id_stage = $Stage->id;
//$substage->save(false);
}
print_r($Substages);*/
/*if(Model::loadMultiple($Substages, Yii::$app->request->post('Stage')[$key]['Substage']) && Model::validateMultiple($Substages))
{
foreach($Substages as $substage){
$substage->id_user = Yii::$app->user->id;
$substage->id_stage = $Stage->id;
$substage->save(false);
}
}*/
}
//die();
}
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', [
'model' => $model,
'criterias' => $criterias,
'stages' => $Stages,
'Substages' => $Substages,
]);
}
Array
(
[_csrf] => J8d1xixQoLbb9BY6JzaHID5kNymEfY6mupCWXTDz4IlN8kCiZTPMx_a5IlRzTvRuUQ5AU80l3PXgx88aAaKs8A==
[Goals] => Array
(
[goal] => купить дом
[date_finish_goal] => 2018-09-06
[criterion_fifnish_goal] => купленный дом
[need_goal] => жить в своем дома
[category_goal] =>
[priority_goal] => 1
[is_public] => 0
[newPicture] =>
)
[date_finish_goal-goals-date_finish_goal-disp] => 6 Сентябрь 2018
[Stage] => Array
(
[0] => Array
(
[title] => wwwww
[description] => frgregrg
[date_finish_stage] => 20.08.2018
)
[Substages] => Array
(
[text] => Array
(
[0] => gregregfrfg
[1] => gregregrgr
)
)
)
)
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