View Route

In yii 1.x view routes were "controler/id", now in Yii2 we have "controler/view?id=ID"

How do I get the url of the old way using the routes correctly?

just enablePrettyUrl




'urlManager' => [

                    'enablePrettyUrl' => true,

                    'showScriptName' => false,                    

                ],



Arash26,

I already did this, but Yii still creates routes with "?id=ID".

Both in ActionColumn as the URL::toRoute () method;

Show relevant code. we can’t see whats wrong there at your machine’s screen!

Stefano,

In any controller:

Yii 1.x


$this->redirect(array('view','id'=>100));

This code returns this url ‘controller/100

Yii 2.x


$this->redirect(['view', 'id' => 100]);

This code returns this url ‘controller/view?id=100

I’d like view urls stay pretty, as in Yii1.x

wrong! according to guide its something like


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

Not sure if its the cause though. Try it and post back.

For me after enabling pretty urls in config everything went pretty.

Do you use advance or basic?

Stefano,

In my reply I omitted the "return", but, yes, I am using the way you spoke.

What matters is the redirection, the methods are the same as in both the Yii1 Yii2, but returned urls are different.

Ps. I’m using basic.

I’m not sure but I think this part of Route not implemented yet