In YII If there is blank space in title which is being used for url, then by default blank spaces are replaced by "+" sign. Something like this:
www.domain.com/event/view/id/Dj+Robag+Ruhme
What I want to do is, I want to replace "+" sign by "-" (dash sign) or by "_" (underscore). Something like this:
www.domain.com/event/view/id/Dj-Robag-Ruhme
or
www.domain.com/event/view/id/Dj_Robag_Ruhme
Right now my urlManager is:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
//'<controller:\w+>/<id:\d+>'=>'<controller>/view',
//'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
//'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
Well, nothing strange since Yii use urlencode
to encode url parameters.
First approach
You could handle this in your model, e.g. :
public function getUrl()
{
return Yii::app()->createUrl('/model/view', array(
'id'=>str_replace(' ', '-', $this->id),
));
}
Don't forget to :
model
with the name of your model,modify your view action in your controller :
public actionView($id)
{
$id = str_replace('-', ' ', $id);
// .....
}
Second approach
You could use your own CUrlRule
class :
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-custom-url-rule-classes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With