regex - avoiding interference between slugs and controller or plugin names in cakephp 2.x router -
i'm looking way avoid interference between slugs , controller/plugin in cakephp url automatically. according article (http://lecterror.com/articles/view/advanced-routing-with-cakephp-one-example) route.php file likes this:
$exceptions = cache::read('exception_url_list'); if ($exceptions===false) { $controllers=app::objects('controller') ; $plugins=app::objects('plugin'); $i=0 ; foreach ($controllers $controller) { $list[$i]=str_replace('controller','',$controller) ; $i++ ; } $exceptions=array_merge($list,$plugins) ; $i=0 ; foreach ($exceptions $value) { $value = inflector::underscore($value); $value = strtolower($value) ; $list[$i]=$value ; $i++ ; } $exceptions=implode('|', $list) ; cache::write('exception_url_list',$exceptions) ; } router::connect('/:language/:typeslug', array('controller' => 'nodetypes', 'action' => 'view'), array( 'language'=>'[a-z]{3}', 'typeslug' => '(?!('.$exceptions.')((\w+)|$))[a-za-z\-_]+/?$', 'pass'=>array('typeslug') ) ); router::connect('/:language/:typeslug/:nodeslug', array('controller' => 'nodes', 'action' => 'view'), array( 'language'=>'[a-z]{3}', 'typeslug' => '(?!('.$exceptions.')((\w+)|$))[a-za-z\-_]+/?$', 'pass'=>array('typeslug','nodeslug') ) );
first route works great second route not cake search controller name same language prefix!
removing typeslug regex in second route solution.
Comments
Post a Comment