2017-12-22 15 views
0

문제가 있습니다. 나는 두 가지 경로가 있습니다

$router->add('/news/{alias:[a-z\-]+}(/?)', array(
     'module' => 'frontend', 
     'controller' => 'news', 
     'action' => 'view', 
     'news_id' => 1, 
     'lang' => 'md', 
))->setName('news_view_short_e'); //=> /news/282334-alias-news 

및 경로 =>/뉴스/색인/:
$router->add('/{lang:[' . $langsDefined . ']{2}+}/{controller:[a-z]{3,50}+}(/?)', array(
    'module' => 'frontend', 
    'controller' => 2, 
    'action' => 'index', 
    'lang' => 1, 
))->setName('default_module_lang'); 

나는이 노선을 사용팔콘 두 개의 단일 경로

. site.com/news/index는 작동하지 않습니다. 하지만 별칭이있는 경로를 제거하면됩니다. site.com/news/index를 잘 활용하십시오. 갈등을 어떻게 해결할 수 있습니까?

답변

0

아마 "alias"매개 변수로 "index"와 일치하기 때문에 첫 번째 규칙이 우선합니다. 정규식을 고치거나 경로를 재정렬하는 것 이외에는 마법의 해결책이 없습니다.

경로 순서를 반대로 변경하면 새로운 문제가 발생하지만 역으로 별칭 대신 컨트롤러와 일치하기 때문입니다. 여기 라우터 그룹을 기본 라우팅을 고수하고 마운트하는 것을 선호

지금 내 라우터의 :

//From my config 
     'router' => array(
      'defaults' => array(
       'namespace' => 'My\\Default\\Namespace\\Controllers', 
       'module' => 'frontend', 
       'controller' => 'index', 
       'action' => 'index' 
      ), 
      'notFound' => array(
       'controller' => 'errors', 
       'action' => 'notFound' 
      ) 
     ), 

// From my service 
$router = new Router(); 
$router->removeExtraSlashes(true); 
$router->setDefaults($this->config->router->defaults->toArray()?: $this->defaults); 
$router->notFound($this->config->router->notFound->toArray()?: $this->notFound); 
$router->mount(new ModuleRoute($this->getDefaults(), true)); 


class ModuleRoute extends RouterGroup 
{ 
public $default = false; 

public function __construct($paths = null, $default = false) 
{ 
    $this->default = $default; 
    parent::__construct($paths); 
} 

public function initialize() 
{ 
    $path = $this->getPaths(); 
    $routeKey = '/' . $path['module']; 
    $this->setPrefix('/{locale:([a-z]{2,3}([\_\-][[:alnum:]]{1,8})?)}' . ($this->default ? null : $routeKey)); 
    $this->add('/:params', array(
     'namespace' => $path['namespace'], 
     'module' => $path['module'], 
     'controller' => $path['controller'], 
     'action' => $path['action'], 
     'params' => 3 
    ))->setName($routeKey); 
    $this->add('/:controller/:params', array(
     'namespace' => $path['namespace'], 
     'module' => $path['module'], 
     'controller' => 3, 
     'action' => $path['action'], 
     'params' => 4 
    ))->setName($routeKey); 
    $this->add('/:controller/([a-zA-Z0-9\_\-]+)/:params', array(
     'namespace' => $path['namespace'], 
     'module' => $path['module'], 
     'controller' => 3, 
     'action' => 4, 
     'params' => 5 
    ))->setName($routeKey); 
    $this->add('/:controller/:int', array(
     'namespace' => $path['namespace'], 
     'module' => $path['module'], 
     'controller' => 3, 
     'id' => 4, 
    ))->setName($routeKey); 
} 
}