Varun Jain
Varun Jain

Reputation: 1911

Custom URL in Yii

I want to configure custom URL in Yii . I am stuck at one last step . This is how I create the URL :

$a->url =  Yii::app()->createUrl('view/profile',array('uid'=>$a->userid,'type'=>$a->type,'specialty'=>$specialty,'locality'=>$locality)) ; 

This is how I have the rule in config file :

'profile<uid:\w+>_<type:\w+>/'=>'view/profile,

This works fine except that the URL which is generated is :

http://localhost/dev/profile122_doctor?specialty=Cardiology&locality=Times+Square

I want the URL to be cleaner , something along these lines :

http://localhost/dev/profile122_doctor/specialty-Cardiology-near-Times-Square

Can this be done ? Any suggestions ? Btw only uid and type variables are actually required for the URL to work correctly . Rest of the info is needed for the purpose of SEO .

Upvotes: 0

Views: 1807

Answers (1)

darkheir
darkheir

Reputation: 8950

You could define your own URL Rule class, this way you'll have more liberty on the syntax:

Using Custom URL Rule Classes in Yii

Upvotes: 2

Related Questions