I apologize in advance if I am asking a newbie question, but I am just starting out with Yii.
I am trying to port a small, incomplete web site from Zend Framework to Yii. I followed the approach explained below to implement support for hyphens in controllers/actions and it seems to work just fine. The only problem I have is that I am not quite sure of where I should place that new class file in order to be autoloaded. I tried to create a folder called /UrlManager under /extensions, but it didn’t work. Finally, I put it in the root of the application and it works… but is that the way to do it? I am assuming there must be a better approach.
You should create a file under protected/components called e.g. CMyUrlManager. Then you have to add this component to your configuration file. In general this is the main.php under protected/config. There is a components-section where you can find a urlManager entry. There you can add a key called class and as value you have to set the name of your UrlManager class.
Mine looks like this:
return array(
// application components
'components' => array(
'user' => array(
//...
),
// uncomment the following to enable URLs in path-format
'urlManager' => array(
'class' => 'CApUrlManager', // < Here you have add your class name!
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),
),
);
Just want to note, using the parseUrl function above often breaks cgridview paging links because they contain dashes (ie, …/ajax/my-cgridview-div-id/…)