Hi,
I have a problem making a redirect function to work from within a controller. The original controller was generated by Gii for create and update actions and it worked fine. But then I updated the create action to use a different model (a custom form model to capture data that spans multiple db tables). After that, the redirect does not work: the create action in db is successful but I get a blank page still with r=cliente/create instead of redirecting to something like r=cliente/view&id=20.
The redirect from update still works.
This is the updated function:
public function actionCreate()
{
$model = new ClienteForm(); // <- changed from 'new Cliente()'
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->cliente_id]);
// return $this->render('view', [ <- this works but the url does not change, stays at r=cliente/create
// 'model' => $this->findModel($model->cliente_id),
// ]);
}
else {
return $this->render('create', [
'model' => $model,
]);
}
}
Can anyone help me understand why?
Thanks,
Mario.