cakephpcakephp-2.0zoneminder

CakePHP - filtering for parameters in the passed URL


I am working with a 3rd party PHP server which has implemented its APIs via CakePHP 2.x

It looks like CakePHP accepts query parameters even if its not specifically been implemented in the controller side.

For example, when I invoke this URL in my browser

https://server/api/logs.json?sort=TimeKey&direction=desc

It returns a descending sorted list based on TimeKey like this:

{"logs":[{"Log":{"TimeKey":"1486576200.482136","Component":"zma_m5","ServerId":"0","Pid":"10931","Level":"0","Code":"INF","Message":"Deck Camera: 4138848 - Opening new event 66155, section start","File":"monitor.cpp","Line":"1532"}} <etc>

I was wondering if its possible to construct a query URL that can also apply a "condition", that is, only show fields where "Code=ERR" without having to change the controller code? Given its 3rd party, my first preference is not to have to change it and handle it via my URL I construct.

The controller implementation is here:

<?php
App::uses('AppController', 'Controller');

/**
 * Logs Controller
 *
 * @property Log $Log
 * @property PaginatorComponent $Paginator
 */
class LogsController extends AppController {

/**
 * Components
 *
 * @var array
 */
    public $components = array('Paginator', 'RequestHandler');
    public $paginate = array(
        'limit' => 100,
        'order' => array( 'Log.TimeKey' => 'asc' ),
        'paramType' => 'querystring'
    );

/**
 * index method
 *
 * @return void
 */
    public function index() {
        $this->Log->recursive = -1;
        $this->Paginator->settings = $this->paginate;

        $logs = $this->Paginator->paginate('Log');
        $this->set(compact('logs'));
    }

    // ...
}

I've been trying various combinations (such as &Code=ERR &Log[Code]=ERR) which don't work. Thanks.


Solution

  • I was wondering if its possible to construct a query URL that can also apply a "condition" [...]

    I'm not familiar with ZoneMinder, but normally that's not possible with the referenced code.

    By default the paginator component only supports the sort, direction, limit and page options.