2017-10-27 2 views
0

젠드 2 & 젠드 3이 문제가 발생했습니다. 다음 코드는 ClassName 클래스를 가져 오지 않았기 때문에 "YourModule \ Controller \ ClassName"을 찾지 못했습니다."예외가 발생했습니다"대신 모든 예외 메시지를 zend에 표시 하시겠습니까?

<?php 
public function indexAction() { 
    $x = new ClassName() ; //I've not imported ClassName, which raise the error. 
} 

일부 예외 이러한 유형의 컨트롤을 발생 onDistpach (DispatchListner)의 캐치 부 간다. 이 catch 블록에 $ ex-> getMessage()를 echo하면 예 : "YourModule \ Controller \ ClassName"을 찾을 수 없습니다..

public function onDispatch(MvcEvent $e) 
{ 
    .... 

} catch (\Throwable $ex) { 
      $caughtException = $ex; //HERE 
     //$ex->getMessage() ; 
} 

하지만 최종 출력물은 다음과 같습니다. 발생한 예외에 대한 정보는 없습니다.

오류가 발생했습니다. 실행 중에 오류가 발생했습니다.

나중에 다시 시도하십시오.

대부분의 다른 경우가 없습니다 예외는 적절한 스택 트레이스를 인쇄 할 수 있습니다. Zend-Mvc에서 DispatchListner를 편집하지 않고 이러한 오류 메시지를 표시하도록 zend를 구성하려면 어떻게해야합니까?

편집 : 내가 error_reporting를 켜기() & display_errors를 바로 예외 전에 시도했다. 또한 예외를 생성하고 여전히 작동하지 않는 코드 주위에 catch 시도해보십시오. 또한 내 module.config. 당신의 module.config.php 파일에 true

'view_manager' => array(
    'display_not_found_reason' => true, 
    'display_exceptions' => true, 
... 
+0

가능한 복제 ([디스플레이의 PHP 오류 젠드 프레임 워크를 사용] https://stackoverflow.com/questions/1201709/display-php-errors-when- using-zend-framework) – Boratzan

+0

또는 https://stackoverflow.com/questions/6392265/how-to-check-full-error-log-in-zend-framework – Boratzan

+0

또는 https://stackoverflow.com/questions/3941860/zend-framework-not-all-errors-are- – Boratzan

답변

-1

설정 display_exceptions :

<?php 
'view_manager' => array( 
'display_not_found_reason' => true, 
'display_exceptions'  => true, // SET TO true 

false로 다시 설정하는 것을 잊지 마세요 때 프로덕션 환경에서 작업.

0

MvcEvent :: EVENT_RENDER_ERROR 및 MvcEvent :: EVENT_DISPATCH_ERROR에 리스너를 연결하여 디스패치 및 렌더링의 예외를 추적 할 수 있습니다. 이것은 ZF3 솔루션이 ZF2에서도 작동 할 수 있습니다.

빨간색 자체 제목 오류 렌더링 기능입니다.

public function exception($e) { 
    echo "<span style='font-family: courier new; padding: 2px 5px; background:red; color: white;'> " . $e->getMessage() . '</span><br/>' ; 
    echo "<pre>" . $e->getTraceAsString() . '</pre>' ; 
} 

가 부트 스트랩에 수신기를 연결

public function onBootstrap(MvcEvent $e) 
{ 
    $eventManager  = $e->getApplication()->getEventManager(); 
    $moduleRouteListener = new ModuleRouteListener(); 
    $moduleRouteListener->attach($eventManager); 

    //Attach render errors 
    $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, function($e) { 
     if ($e->getParam('exception')) { 
      $this->exception($e->getParam('exception')) ; //Custom error render function. 
     } 
    }); 
    //Attach dispatch errors 
    $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function($e) { 
     if ($e->getParam('exception')) { 
      $this->exception($e->getParam('exception')) ;//Custom error render function. 
     } 
    }); 
} 
관련 문제