sadboys Posted September 6, 2017 Share Posted September 6, 2017 Hi everyone! In my Ticket _form.php. When I create ticket it gets the current time and fills in the time_start field automatically, in order to fill in the field time_end I need to update the ticket which also gets the current time when you update it. My problem is when I update it the time_start also updates and now they have the same value which supposed to be different. I have this in my form: <?= $form->field($model, 'time_start')->textInput(['readOnly' => true]) ?> <?= $form->field($model, 'time_end')->textInput(['readOnly' => true]) ?> Which automatically gets the current time of the system In my TicketController.php public function actionCreate() { $model = new Ticket(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { $model->time_start = date('y-m-d h:i:s'); return $this->render('create', [ 'model' => $model, ]); } } /** * Updates an existing Ticket model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { $model->time_end = date('y-m-d h:i:s'); return $this->render('update', [ 'model' => $model, ]); } } Link to comment https://forums.phpfreaks.com/topic/304889-yii2-both-fields-update/ Share on other sites More sharing options...
Barand Posted September 6, 2017 Share Posted September 6, 2017 Do NOT double post topics - read the rules. Link to comment https://forums.phpfreaks.com/topic/304889-yii2-both-fields-update/#findComment-1550868 Share on other sites More sharing options...
Recommended Posts