System
CakePHP 2.x
Code
Model/Foo.php
<?php
App::uses('AppModel', 'Model');
/**
* Foo Model
*
*/
class Foo extends AppModel {
/**
* @var array
*/
public $findMethods = array(
'customFindType' => true,
);
/**
* @param $state
* @param $query
* @param array $results
* @return array
*/
public function _findCustomFindType($state, $query, $results = array()) {
if ($state === 'before') {
// Custom find type
return $query;
}
return $results;
}
}
Controller/FoosController.php
<?php
App::uses('AppController', 'Controller');
/**
* Foos Controller
*
* @property Foo $Foo
* @property PaginatorComponent $Paginator
* @property SessionComponent $Session
*/
class FoosController extends AppController {
/**
* Components
*
* @var array
*/
public $components = array('Paginator', 'Session');
/**
* index method
*
* @param null $findType
* @return void
*/
public function index() {
$this->Foo->recursive = 1;
$this->Paginator->settings = array(
'Foo' => array(
'findType' => 'customFindType'
)
);
$foos = $this->Paginator->paginate('Foo');
$this->set(compact('foos'));
}