Hello,
I have a form on which (among other values) the user has to select the amount of inserts that will be made and the date of the first insert.
I want that only the first insert has the selected date and the rest have intervals (which also will be selected by user)
Example: In the form I choose to insert 3 elements, and the interval to 5 days, starting by 10-apr-2016. Insert 2 should be with date 15-apr-2016 and insert 3 with date 20-apr-2016.
This is what I got in the Controller (of course I’ve not included the interval variable yet) I just want to know how do I add the interval from the base date.
public function actionCreate()
{
$model = new Spraying();
$post = Yii::$app->request->post();
if (isset($post) && isset($post[$model->formName()]))
{
$cantidad = $post[$model->formName()]['cantidad'];
$inicio = $post[$model->formName()]['fecha_inicio'];
$aplicado = $post[$model->formName()]['aplicado'];
$receta = $post[$model->formName()]['receta_id'];
$programa = $post[$model->formName()]['programa_id'];
$nombre = "spraying-";
for ($i = 1; $i <= $cantidad; $i++) {
//if (!isset($cantidad)) { continue; }
Yii::$app->db->createCommand()->insert('spraying', [
'numero_spraying' => $nombre.$i,
'fecha_inicio' => $inicio,
'aplicado' => $aplicado,
'programa_id' => $programa,
'receta_id' => $receta,
])->execute();
}
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}