2013-08-15 1 views
0

cakephp url의 슬러그와 컨트롤러/플러그인 간의 간섭을 피하는 방법을 찾고 있습니다. 이 문서에 따라과 (http://lecterror.com/articles/view/advanced-routing-with-cakephp-one-example) 내 route.php 파일은 다음을 추천했습니다 :cakephp 2.x 라우터에서 슬러그와 컨트롤러 또는 플러그인 이름 사이의 간섭을 피하십시오.

$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') 
     ) 
    ); 

첫 번째 경로는 언어 접두사와 동일한 컨트롤러 이름의 케이크를 검색 할 수 없습니다 큰하지만 두 번째 경로를 작동합니다!

답변

1

두 번째 경로에서 TypeSlug 정규식을 제거하는 것이 해결책입니다.