2014-09-22 3 views
0

내가 ZF2에 기본 라우팅 문제에 봉착 : 나는 URL/API/hostbill/후크/non_existent_action URL을 호출 할 때젠드이 기본 경로

내가 원하는 무엇
'router' => array(
    'routes' => array(
     'hostbill-api' => array(
      'type' => 'Literal', 
      'options' => array(
       'route' => '/api/hostbill', 
       'constraints' => array(
        'service' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'call' => '[a-zA-Z][a-zA-Z0-9_-]*', 
       ), 
       'defaults' => array(
        '__NAMESPACE__' => 'Hostbill\Controller', 
        'controller' => 'Api', 
        'action'  => 'index', 
       ), 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
       'hostbill-api-service' => array(
        'type' => 'Segment', 
        'options' => array(
         'route' => '[/:service[/:call]]', 
         'constraints' => array(
          'service' => '[a-zA-Z][a-zA-Z0-9_-]*', 
          'call' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         ), 
        ), 
       ), 
       'hostbill-api-hook' => array(
        'type' => 'Segment', 
        'options' => array(
         'route' => '/hook[/:action]', 
         'constraints' => array(
          'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         ), 
         'defaults' => array(
          '__NAMESPACE__' => 'Hostbill\Controller', 
          'controller' => 'Hook', 
          'action'  => 'index', 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
), 

, 그것의의 기본값은입니다.

사실 내가 기존 작업을 호출하면 라우팅이 작동하지만, 존재하지 않는 후크 작업을 사용하면 기본값이 호출되지 않고 404가 실행됩니다.

는 어떤 도움을 컨트롤러에 넣고

답변

0

을 apreciated :

/** 
* Create an HTTP view model representing a "not found" page 
* 
* @param HttpResponse $response 
* @return ViewModel 
*/ 
protected function createHttpNotFoundModel(HttpResponse $response) 
{ 
    return $this->indexAction();//or whatever that is your default action is 
} 

또는이 하나

/** 
* Action called if matched action does not exist 
* 
* @return array 
*/ 
public function notFoundAction() 
{ 
    return $this->indexAction();//or whatever that is your default action is 
} 
+0

좋은를! 이벤트를 사용하는 대신이 일을 그렇게 많이하는이 방법을 좋아하십시오. – kitensei