【问题标题】:Show validation errors in crud api在 crud api 中显示验证错误
【发布时间】:2017-08-08 07:58:45
【问题描述】:

如何在返回的响应中显示验证错误和消息。 我只是像这样检索响应:

{
  "message": "4 validation errors occurred",
  "url": "/api/posts",
  "code": 422
} 

【问题讨论】:

    标签: api validation debugging cakephp-3.0 crud


    【解决方案1】:

    我找到了here:

    异常处理程序需要配置:

    -如果您的 CakePHP >= 3.3(中间件功能):

    'Error' => [
        'errorLevel' => E_ALL,
        'exceptionRenderer' => 'Crud\Error\JsonApiExceptionRenderer',
        'skipLog' => [],
        'log' => true,
        'trace' => true,
    ],
    

    -如果你的 CakePHP

    <?php
    class AppController extends Controller {
    
      public function initialize()
      {
        parent::initialize();
        $this->Crud->config(['listeners.api.exceptionRenderer' => 'App\Error\ExceptionRenderer']);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-29
      • 1970-01-01
      • 2020-12-30
      • 2015-10-26
      • 2013-06-09
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多