CakePHP 2: New Exceptions

I would like to create a new exception called SecurityException. Where should I put the code?

class SecurityException extends CakeException {}; 

Thanks!

+6
source share
2 answers

Create an exceptions.php file, put it in the Lib folder and fill it with all the *Exception classes. Then include it in the application boot file.

require APP . 'Lib' . DS . 'exceptions.php';

All exceptions will become available for widespread use.

+8
source

I followed the Lukhomolina 2nd answer (commented on his own answer), and considered that he deserved an official answer:

Here's another approach: "throwing exceptions in ([plugin-if-any]) / Lib / Error / Exception / NameOfTheException.php and using App :: uses ('NameOfTheException', 'Error / Exception') is necessary. It seemed that it's Cake'ish's way of doing it, and they are not included if no one has been cast. " -luchomolina

+1
source

Source: https://habr.com/ru/post/898846/


All Articles