Hello.
There is, for example, a User model. In the database, there is a user table and there is a data field (it includes the date and time. The record has the form 01.01.2018 13:00:00).
I created the start_data and start_time fields in the user model.
How it will be correct to make a method which will pull out date and will break it into two fields start_date and start_time? This is necessary in order to be able to edit the start date separately through the form, separately the start time.
I imagine that it will look like this in a model.
public function createStartDate(){ $arrDateAndTime = explode(" ",$this->date); $start_date = $arrDateAndTime[0]; return ['start_date' => $start_date]; } public function createStartTime(){ $arrDateAndTime = explode(" ",$this->date); $full_start_time = explode(':',$arrDateAndTime[1]); $start_time = $full_start_time[0] . ":" . $full_start_time[1]; return ['start_time' => $start_time]; } How will it be necessary to return the correct fields so that they are displayed in the form?
In the controller, I simply call the desired model by id:
public function actionIndex() { $user = User::findOne(540); return $this->renderAjax('userchange',['user' => $user]); } Fields in the view has the form:
echo $form->field($user, 'start_date'); echo $form->field($user, 'start_time');