How do I use a custom finder with pagination?


I am guessing this is simple, but I can’t get it to work. I have created a custom finder, customlist, in the Car model and using
returns exactly what I expect. But it needs to be used in this existing function:

public function index() {
$this->Car->recursive = 0;
if (!empty($this->request->query[‘search’])) {
$term = ‘%’ . $this->request->query[‘search’] . ‘%’;
$this->Paginator->settings[‘conditions’][‘OR’] = array(
‘Car.desc LIKE’ => $term,
‘Car.model LIKE’ => $term);
$this->set(‘Cars’, $this->paginate());

I tried adding ‘customlist’ as an argument for paginate, didn’t work.
I tried adding the line
$this->Paginator->settings['findType'] = 'customlist';
just before the paginate line, that also didn’t work,
How do I get this function to use my custom finder?
(This is Cake 2.X)

Additional info:
It appears that adding the findType line as described above, is close. I can see that the correct SQL statement has been executed. But the Cake log has this:

2017-05-04 19:09:49 Error: [Error] Unsupported operand types
Request URL: /cars
Stack Trace:
#0 /media/sf_GIT/insight/app/Vendor/cakephp/cakephp/lib/Cake/Controller/Controller.php(1089): PaginatorComponent->paginate(Object(Car), Array, Array)
#1 /media/sf_GIT/insight/app/Controller/CarsController.php(31): Controller->paginate()
#2 [internal function]: CarsController->index()
#3 /media/sf_GIT/insight/app/Vendor/cakephp/cakephp/lib/Cake/Controller/Controller.php(491): ReflectionMethod->invokeArgs(Object(CarsController), Array)
#4 /media/sf_GIT/insight/app/Vendor/cakephp/cakephp/lib/Cake/Routing/Dispatcher.php(193): Controller->invokeAction(Object(CakeRequest))
#5 /media/sf_GIT/insight/app/Vendor/cakephp/cakephp/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke(Object(CarsController), Object(CakeRequest))
#6 /media/sf_GIT/insight/app/webroot/index.php(98): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#7 {main}

Line 31 refers to the paginate() line.


Ok, the only way I could get this to work was to move the custom query into the controller, using
$this->Paginator->settings = array(
While this works, it seem like a violation of MVC…


findType is what you need so I would advice to dig into why it’s not working in your case. Someone might be able to help you out if you pasted here your custom finder code.