Sunday, 15 July 2012

Yii2 create user friendly URL with parameters -


Hi, I have to make user friendly url, but when it is to experiment with parameters which is not working.

URL:

  URL :: from (['site / index', 'id' = gt; 1]);  

The URL looks like this:

  localhost / test app / frontend / web / index.fp / site / index? Id = 1  

/forntend/config/main.php

  'urMManager' = & gt; ['Class' = & gt; 'Yii \ web \ UrlManager', 'enablePrettyUrl' = & gt; True, // 'showScriptName' = & gt; Wrong, 'rule' = & gt; [],],  

I like an output

  localhost / test application / frontend / web / index.php / site / index / id / 1  

and then how to use the ID value in the controller.

  'rule' = & gt; ['Site / Index / ID / & lt; Id: \ d + & gt; ' = & Gt; 'Site / Index' // 'Site / Index / & lt; Id: \ d + & gt; ' = & Gt; 'Site / Index' Better Solution // '& lt; Controller & gt; / & Lt; Action & gt; / & Lt; Id: \ d + & gt; ' = & Gt; '& Lt; Controller & gt; / & LT; Action & gt; ' Will be applied to all controllers and operations],  

.

And in your action:

  Public Function Action Index ($ ID) {...}  

No comments:

Post a Comment