Adding dash to actions. (e.g. http://yii.com/admin/add-account)

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>',

			),

		),

	),

);

Hey guys I tried adding url rules to my Url Manager:




'<controller:[\w\-]+>/<action:[\w\-]+>/<id:\d+>'=>'<controller>/<action>',

'<controller:[\w\-]+>/<action:[\w\-]+>'=>'<controller>/<action>',	



or




'<controller:[a-zA-Z_\-]+>/<action:[a-zA-Z_\-]+>/<id:\d+>'=>'<controller:[a-zA-Z_\-]+>/<action>',

'<controller::[a-zA-Z_\-]+>/<action:[a-zA-Z_\-]+>'=>'<controller:[a-zA-Z_\-]+>/<action>',



I still get 404.

I think I’m doing something wrong with action names inside controller or names of view files.

my view file:

client-update.php

my action name inside Controller

"actionClientUpdate()"

Where am I going wrong with this?

Does anyone know if this functionality has been added to Yii?

Just want to note, using the parseUrl function above often breaks cgridview paging links because they contain dashes (ie, …/ajax/my-cgridview-div-id/…)

Looking for a “route dashed url” implementattion I’ve also found this related yii wiki article:

http://www.yiiframework.com/wiki/404/hyphenation-of-routes-in-url-management/

How come we can’t just create an action with underscore, for example:


public function actionEdit_Account()

{


}

And accessing URL:


/account/edit-account/

should automatically route to this action?

I have a URL like this


www.mydomain.com/post/update-post/3

I cant pass id to my action method


actionUpdatePost($id)

How to pass id from missingAction to update method