Skip to content

Instantly share code, notes, and snippets.

@tigrang
Created December 6, 2012 08:35
Show Gist options
  • Save tigrang/4222765 to your computer and use it in GitHub Desktop.
Save tigrang/4222765 to your computer and use it in GitHub Desktop.
<?php
App::uses('CakeRoute', 'Routing/Route');
class HyphenRoute extends CakeRoute {
public function parse($url) {
if ($route = parent::parse($url)) {
if (strtolower($route['action'] !== $route['action'])) {
throw new NotFoundException();
}
if (strpos($route['action'], '-') !== false) {
$route['action'] = Inflector::variable(str_replace('-', ' ', $route['action']));
}
}
return $route;
}
protected function _writeUrl($params) {
$params['action'] = str_replace('_', '-', Inflector::underscore($params['action']));
return parent::_writeUrl($params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment