2016-08-03 7 views
0

が存在するかどうかを確認する方法:ZF2 - 子供を持つルートは、このルートを考える

'country' => array(
      'type' => 'Zend\Mvc\Router\Http\Segment', 
      'options' => array(
       'route' => '/1country', 
       'defaults' => array(
        'controller' => 'Index', 
        'action'  => 'country', 
        'country_id'  => '5', 
       ), 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
         'city' => array(
          'type' => 'Zend\Mvc\Router\Http\Segment', 
          'options' => array(
           'route' => '/1city', 
           'defaults' => array(
            'controller' => 'Index', 
            'action'  => 'city', 
            'city_id'  => '4', 
           ), 
          ), 
         ), 

      ), 
     ), 

私がしなければ:

$this->getServiceLocator()->get('Router')->hasRoute('country'); //true 
$this->getServiceLocator()->get('Router')->hasRoute('country/city'); //false 

を両方に該当する必要がありますが...任意のアイデア?

+0

なぜそのような行動を必要としますか? – newage

+0

は説明が複雑ですが、基本的には最適化されたルートがあり、最適化されたルートはありません。存在していれば、最適化されたSEOルートには最適化されたルートはリダイレクトされません。その親ルート上でhasRouteを実行します。 – peterpeterson

答えて

1

これを試してみてください:

// explode if child.. 
$route = 'home/default'; 
$names = explode('/', $route, 2); 

// use 
/* @var Router $router */ 
$router = $container->get('Router'); 

if (!$router->hasRoute($names[0])) { 
    // ... 
} 
関連する問題