please can you add build-in support for controller actions having dash in the action name?
Then
http://www.mysite.com/cms/products-and-services
would be routed to method "actionProductsAndServices" inside of "CmsController".
Here is a workaround applicable to Yii 1.X.X, that unfortunatelly will not highlight CMenu active item:
/**
* Catch all action - used as a workaround to support dashed action names like my-action => actionMyAction (compatible with Zend Framework)
* @param string $action Action that was not found within this controller
*/
public function missingAction($action){
$action = explode('-', $action);
$action = array_map('strtolower', $action);
$action = array_map('ucfirst', $action);
$action = implode('',$action);
if(method_exists($this,'action'.$action) || array_key_exists('action'.$action, $this->actions())){
$this->setAction($action);
$this->run($action);
}else{
throw new CHttpException(404, Yii::t('main','Action "{action}" does not exist in "{controller}".', array(
'{action}' => 'action'.$action,
'{controller}' => get_class($this),
)));
}
}
Actually if possible, I would love to see this support also for controller names, like
Adding more functionality/magic doesn’t sound good. It’s not like “strip those dashes” would be the only case to cover? Maybe for your application, but not for others. So I suggest to define those rules manually or alternatively use a custom url rule class that does the stripping.
Agree with this, when creating a site we shouldn’t have to write out 100’s of url rules either so thats not a solution. This can be implemented easily enough with backward compatibility. Also according to most SEO standards dashes are the accepted method and the most used method around the internet.