2017-12-22 14 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'); 

私はこれらのルートを使用して私は2つのルートがあります。 site.com/news/indexは機能しません。しかし、私が別名でルートを削除する場合。 site.com/news/indexをうまく処理してください。どのように私は紛争を解決できますか?ファルコン2つの単一ルート

答えて

0

"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); 
} 
} 
関連する問題