action with hyphen

what would be the controller and function name to get a url looking like my-controller/my-action ?

Well, i think you should create a route to map this kind of id into mycontroller/myaction

No, he want it with hyhpen. He can't create neither class nor method with dash in it. You can use CUrlManager to achieve this.

Alternative way is to attach handler to the onbeginRequest (http://www.yiiframework.com/doc/api/CApplication#onbeginRequest) and preprocess the route removing hyphens. If you do so, then Built-in CApplication mechanism will dispatch it to mycontroller/myaction

How about using .htaccess rewriting rule?

propose one :)

@KJedi

Can you please provide an example on how to do that alternative way of yours to solve this? And what about if there isn’t a controller specified on the URL (e.g. www.yourdomain.com/my-action/)?

How about this approach:


'urlManager'=>array(

    'urlFormat'=>'path',

    'rules'=>array(

        'my-<controller>/my-<action>'=>'<controller>/<action>',

        'my-<controller>'=>'<controller>',

    ),

),



I know this is a pretty old thread, but it was one of the first I found on google, so I will post my answer here.

I made a simple extension to the CUrlManager class.

Config:




'urlManager' => array(

	'class' => 'QUrlManager',

	...

)

QUrlManager:




<?php


class QUrlManager extends CUrlManager

{

	public function parseUrl($request)

	{

		// get uri

		$uri = parent::parseUrl($request);

		// remove hyphens

		return str_replace('-', '', $uri);

	}

}



Hopes this helps someone!

Support for action name with dash is not currently supported by Yii:-(

Check out this workaround:

http://www.yiiframework.com/forum/index.php?/topic/14990-adding-dash-to-actions-eg-httpyiicomadminadd-account/