How can I populate the CRUD update form with data saved in to a json encode array into a single DB field?
My are my array field in my CRUD create form
<?= $form->field( $model, 'seo_information[seo_title]' )->textInput( [ 'maxlength' => 255 ] )->label('Meta Title') ?>
<?= $form->field($model, 'seo_information[meta_description]')->textInput(['maxlength' => 60])->label('Meta Description') ?>
<?= $form->field($model, 'seo_information[keywords]')->textInput(['maxlength' => 160])->label('Keywords') ?>
And then within my create function (which needs improving)
public function actionCreate()
{
$model = new Article();
$model->user_id = Yii::$app->user->id;
if ($model->load(Yii::$app->request->post()))
{
$seo_information = $_POST['Article']['seo_information'];
$model->seo_information = json_encode($seo_information);
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
else
{
return $this->render('create', [
'model' => $model,
]);
}
}