public function actionCreate()
{
$model = new Goals;
$Stages = [new Stage()];
$criterias = CriteriesGoals::find()->all();
$Substages = new Substage;
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;
}
}
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);
}
}
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', [
'model' => $model,
'criterias' => $criterias,
'stages' => $Stages,
'Substages' => $Substages,
]);
}
form.find(':input[data-picker=datepicker]').removeClass('hasDatepicker');
form.find(':input[data-picker=datepicker]').not('.hasDatePicker').datepicker();
$count = count(Yii::$app->request->post('Stage', []));
$stages = [new Stage()];
for($i = 1; $i < $count; $i++) {
$stages[] = new Stage();
}
if ($model->load(Yii::$app->request->post())) {
$model->doc = UploadedFile::getInstance($model, 'doc');
if ($model->doc) {
if($model->upload())
{
$model->doc = $model->doc->baseName.'.'.$model->doc->extension;
}
}
if($model->save())
{
/* if($stages)
{
if (Model::loadMultiple($stages, Yii::$app->request->post()) && Model::validateMultiple($stages)) {
foreach ($stages as $stg) {
$stg->id_user = $model->id_user;
$stg->goal_id = $model->id;
$stg->save(false);
}
}
} */
return $this->redirect(['view', 'id' => $model->id]);
}
}