How to show zf2 errors?

こ雲淡風輕ζ 提交于 2019-12-01 14:26:22

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

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

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

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"

Add this to your public/index.php

error_reporting(E_ALL | E_STRICT);

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!