Problem with Controller Redirect


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?



Your url changes when you use redirect.Render only render a particular page,here url wont change.

poda…you put the code

Yes, but Why does redirect does not work with my updated function?

read this:

As the documentation says you need to use the ‘GET’ method to access this variable.

return $this->redirect(['view', 'id' => $model->cliente_id]);

echo "This is my variable - ".$_GET['id'];  


I read through the referenced document, however I don’t believe that applies to my controller logic. I have create and update action the same controller. Both of them redirect to the detail view. When redirecting from update action, it works fine (and there is no need to reference $_GET in the view to get the model attributes). When redirecting from the create action, it does not work. The URL does not even change, it remains as r=cliente/create…

I think that redirection is not even being executed for some reason. How can debug this?