How to show zf2 errors?

2019-02-21 01:49发布

问题:

I've reinstall my system and now when something wrong in zf2 i cant see the error on the page only in nginx error log, the display_errors On and display_startup_errors On, in php.ini, maybe something with my php-fpm settings? And in the simple php file not in zf2 i have see the errors!

回答1:

You need enable the following options in your config

'view_manager' => array(
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
)

Remember turn off this in a production environment



回答2:

ini_set('display_errors', true); in my index.php now show me the errors



回答3:

Zend framework 2 will merge configs from all loaded modules, so you need to ensure that you already set 'display_exceptions' (if that key exists) to true in all modules's config file.

'view_manager' => array(
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
)

You can see which modules are loaded in your application.config.php file



回答4:

You can combine the above with an environment check:

Add this to your public/index.php at the top:

$env = getenv('APP_ENV') ?: 'production';
if($env == "development") {
  error_reporting(E_ALL | E_STRICT);
  ini_set('display_errors', true);
}

And this one to your public/.htaccess:

SetEnv "APP_ENV" "development"



回答5:

Add this to your public/index.php

error_reporting(E_ALL | E_STRICT);


回答6:

In my case Zend errors and NGinX - php5 fpm, work like this:

Only I put in public/index.php (@AlloVince)

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

Without If(){...}

But If only to put above code, display error, will give this:

Parse error: syntax error, unexpected '}', expecting ',' or ';' in /usr/local/nginx/html/ZendSkeletonApplication/module/Album/src/Album/Controller/AlbumController.php on line 12

Another thing! Set up this code: (@To Nong)

'display_not_found_reason' => true,
'display_exceptions'       => true,

in module.config.php like this:

'view_manager' => array(
 'template_path_stack' => array(
     'album' => __DIR__ . '/../view',
     'display_not_found_reason' => true,
     'display_exceptions'       => true,
 ),

),

I get all errors of an error log on screen:

Fatal error: Uncaught exception 'Zend\View\Exception\InvalidArgumentException' with message 'Invalid path provided; must be a string, received boolean' in /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/View/Resolver/TemplatePathStack.php:201 Stack trace: #0 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/View/Resolver/TemplatePathStack.php(149): Zend\View\Resolver\TemplatePathStack->addPath(true) #1 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/Mvc/Service/ViewTemplatePathStackFactory.php(38): Zend\View\Resolver\TemplatePathStack->addPaths(Array) #2 [internal function]: Zend\Mvc\Service\ViewTemplatePathStackFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'viewtemplatepat...', 'ViewTemplatePat...') #3 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(939): call_user_func(Array, Object(Zend in /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 946

I didn't touch config file as php-fpm in system (Ubuntu 14.04).