Throwing a custom 503 exception in CakePHP 2

后端 未结 2 1033
-上瘾入骨i
-上瘾入骨i 2020-12-20 03:37

I need to give a 503 Service Unavailable HTTP header.

Normally I use these for 404 and 500 codes

throw new NotFoundException();
         


        
相关标签:
2条回答
  • 2020-12-20 04:23

    The Exceptions page in the Cake 2.0 book is worth a read.

    Here's my short test:

    // in bootstrap.php
    require(APP . 'Lib' . DS . 'MyExceptions.php');
    
    
    // in /Lib/MyExceptions.php
    class ServiceUnavailableException extends CakeException {
    
        protected $_messageTemplate = 'Test';
    }
    
    // in controller
    throw new ServiceUnavailableException('Service unavailable', 503);
    
    0 讨论(0)
  • 2020-12-20 04:38

    http://api22.cakephp.org/class/cake-response#method-CakeResponsestatusCode

    Will allow you to set a status code.

    0 讨论(0)
提交回复
热议问题