Created
August 3, 2012 00:10
-
-
Save tigrang/3242448 to your computer and use it in GitHub Desktop.
Hyphenated actions in urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('CakeRoute', 'Routing/Route'); | |
class HyphenRoute extends CakeRoute { | |
public function parse($url) { | |
if ($route = parent::parse($url)) { | |
// don't allow camel-case actions in url to prevent duplicate urls pointed to same page | |
if (strtolower($route['action'] !== $route['action'])) { | |
throw new NotFoundException(); | |
} | |
// convert hyphenated action back to camel-case | |
if (strpos($route['action'], '-') !== false) { | |
$route['action'] = Inflector::camelize(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