Question

i'm looking for a way to avoid interference between slugs and controller/plugin in cakephp url automatically. with according to this article (http://lecterror.com/articles/view/advanced-routing-with-cakephp-one-example) my 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 as $controller) {
        $list[$i]=str_replace('Controller','',$controller) ;
        $i++ ;
    }
    $exceptions=array_merge($list,$plugins) ;
    $i=0 ;
    foreach ($exceptions as $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 but second route not the cake will search for a controller name same as language prefix!

Était-ce utile?

La solution

removing TypeSlug regex in second route is the solution.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top