Tuesday, March 8, 2022

[FIXED] Yii url manager only ID in url

Issue

i have in YII for example domain: www.example.com/product-url-1234

how to set rules in urlManager and how to use controller/action/id


Solution

If you want to use this url www.example.eu/product-url-1234

and suppose 'index' is the name of the action of the 'user' controller that will handle the request

Then create a rule like

'<id:.*?>'=>'user/index'

Now if you will use Yii::app()->createUrl('user/index',array('id'=>'product-url-1234'))

then it will give you the desired result.

And if you Visit this Url, User/Index will handle the request.



Answered By - Let me see

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.