I have tried everything I can think of to stop errors from displaying in CakePHP. I have checked the CakePHP instruction manual and have searched the internet and stackoverflow for phrases like "turn off error reporting in CakePHP" and "turn off debug mode in CakePHP". Here's a description of the errors that are still displaying and what I have tried to hide these errors in CakePHP:

Errors I'm Still Getting

  • Error One: I intentionally declared a variable incorrectly in one of my Controller classes to test whether errors were displaying, and received "Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in (file paths and line number)"

  • Error Two: I tried typing a bunch of gibberish into the URL as a test to see if it would display an error. I get a "Missing Controller" error from Cake.

Things I've Tried to Stop Errors from Displaying

  • Configure::write('debug', 0); (edited to zero) in \app\Core.php

  • error_reporting(0); (added the line) in \app\Config\bootstrap.php

  • Configure::write has a 'level' key in an array in \app\Core.php so I changed it from "E_ALL & E_DEPRECATED" to 0. Then I tried blanking it out.

  • Added a php.ini file to public_html which contained a whole pile of commands to turn off errors. I also deleted this file to make sure it had not been there all along interfering.

  • Commented out sections of ___construct() in \lib\Cake\Utility\Debugger.php (this removed error messages out of the title tags of the page that shows up when gibberish is typed into the url but not the missing controller error). By the way, error messages were being put into the HTML titles. That's weird.

  • Commented out echo $self->outputError($data); in showError in \lib\Cake\Utility\Debugger.php

  • Double checked the manual's "Deployment" page, which referred me to the "Debug" page. That page talked about setting "Configure::debug", which is written slightly differently from "Configure::write('debug', 0);" so I tried variations.

  • I searched all directories containing php for the phrases "error_reporting(" and "ini_set(" to ensure I hadn't enabled errors somewhere in there and forgotten.

If anyone has any idea why these are still displaying despite all that I've tried or what can be done to turn them off, I would appreciate it very much.

Thanks.

有帮助吗?

解决方案

I tried Mark's suggestion, which worked. When I searched my entire Cake installation for "Configure::write('debug'", I found tons of lines to turn debugging on - although most of these were present in the original files as downloaded from the official CakePHP site. As an experiment, I made a copy of my Cake installation, changed all instances that set debug higher than 0, and that worked. Then, assuming that some of them should be there, and not being sure which were supposed to be there, I decided to completely delete CakePHP, download a fresh copy, and replace it.

After I configured the new core.php, the missing controller error was replaced with a not found error, and the parse error that I intentionally caused for testing purposes was replaced with an internal server error. I'm not sure that showing an internal server error is what it is supposed to do... but the behavior did change after editing the debug setting, and it doesn't reveal the file paths anymore. So, I guess that it's behaving the way that it's supposed to.

I would like to give Mark credit for helping me solve this, but he only posted a comment.

其他提示

i think there is some options for u :

  1. Configure your errors

    here you go app/Config/core.php

    Configure::write('Error', array( 'handler' => 'ErrorHandler::handleError', 'level' => E_ALL & ~E_DEPRECATED, 'trace' => true )); You have 5 built-in options when configuring error handlers:

handler - callback - The callback to handle errors. You can set this to any callable type, including anonymous functions.

level - int - The level of errors you are interested in capturing. Use the built-in php error constants, and bitmasks to select the level of error you are interested in.

trace - boolean - Include stack traces for errors in log files. Stack traces will be included in the log after each error. This is helpful for finding where/when errors are being raised.

consoleHandler - callback - The callback used to handle errors when running in the console. If undefined, CakePHP’s default handlers will be used.

  1. create error handler as your own

    //in app/Config/core.php

    Configure::write('Error.handler', 'AppError::handleError');

//in app/Config/bootstrap.php

`App::uses('AppError', 'Lib');`

//in app/Lib/AppError.php

class AppError { public static function handleError($code, $description, $file = null, $line = null, $context = null) { echo 'There has been an error!'; } }

This class/method will print out ‘There has been an error!’ each time an error occurs. Since you can define an error handler as any callback type, you could use an anonymous function if you are using PHP5.3 or greater.:

Configure::write('Error.handler', function($code, $description, $file = null, $line = null, $context = null) {
    echo 'Oh no something bad happened';
});

also u can see here for more help

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top