Fork me on GitHub
Heads up!
These docs are for Crud v3 - that only works with CakePHP 2.x. For CRUD v4 docs please go to the new documentation site
The CRUD v4 documentation has been completely rewritten, and since CRUD v3 and CRUD v4 API is ~95% identical, it may be worth a look for CRUD v3 users as well until v4 docs are backported for v3.
...toc....

Api Query Log

Adds query log output to Api responses

Setup

This feature requires the Api listener to work

This listener will only append the queryLog key if debug is 2 or greater

Attach it on the fly in your controller beforeFilter

This is recommended if you want to attach it only to specific controllers and actions

<?php
class SamplesController extends AppController {

  public function beforeFilter() {
    $this->Crud->addListener('Api');
    $this->Crud->addListener('ApiQueryLog');
  }

}
?>

Attach it using components array

This is recommended if you want to attach it to all controllers, application wide

<?php
class SamplesController extends AppController {

  public $components = [
    'RequestHandler',
    'Crud.Crud' => [
      'actions' => ['index', 'view'],
      'listeners' => ['Api', 'ApiQueryLog']
    ];

}
?>

Configuration

The listener do not have any configuration options

This listener will only append the queryLog key if debug is 2 or greater

Example output

{
   "success": true,
   "data": [

   ],
   "queryLog": {
      "default": {
         "log": [
            {
               "query": "SELECT SOMETHING FROM SOMEWHERE",
               "params": [

               ],
               "affected": 25,
               "numRows": 25,
               "took": 0
            },
            {
               "query": "SELECT SOMETHING FROM SOMEWHERE'",
               "params": [

               ],
               "affected": 1,
               "numRows": 1,
               "took": 0
            }
         ],
         "count": 2,
         "time": 0
      }
   }
}



comments powered by Disqus