In Yii, is it possible to use the router rule to "translate" a keyword in a URL to a certain action's $_GET Parametric?
What I want, is to let this URL:
http://example.com/MyModule/MyController/index/foo
to point to:
http://example.com?r=MyModule/MyController/index&id=12
where foo points to 12.
And, since I am using "path" urlFormat, and are using other url rules to hide index and id=, the URL above should eventually point to:
http://example.com/MyModule/MyController/12
Is this possibe by setting rules in the config file for urlManager component?
Your action should accept a parameter
$id:What you need to do, is to modify the loadModel function in the same controller:
Then, you will need to modify the urlManager rules to accept a string, instead of just an ID:
Remove
:\d+in the default rule below:It should be like this:
One more thing to note, if you are going this path, make sure slug is unique in your database, and you should also enforce the validation rule in the model: