I’m using the WP MVC plugin to create a plugin which provides a database of names as part of my WordPress website.
The below controller retrieves the right information from 2 database tables, but suddenly pagination is not working anymore. Do I need to use paginate() instead of find()? If yes, how would a similar query look using paginate()? Unfortunately there are no examples available.
Thanks!
names_controller.php
<?php
class NamesController extends MvcPublicController {
public function index() {
$objects = $this->Name->find(array(
'joins' => array('Origin'),
'selects' => array('Origin.id', 'Origin.origin', 'Name.id', 'Name.name', 'Name.gender', 'Name.meaning', 'Name.origin_id'),
'page' => 1,
'per_page' => 20,
'conditions' => array(
'Name.name LIKE' => 'A%'
)
));
$this->set('objects', $objects);
}
}
?>
=================== UPDATE ======================
I replaced the find() with paginate() unfortunately the join doesn’t work anymore. Furthermore it IGNORES e.g. page, per_page etc parameters.
Anyone an idea?
$params = $this->params;
$params['page'] = empty($this->params['page']) ? 1 : $this->params['page'];
$params['per_page'] = 20;
$params['joins'] = array('Origin');
$params['selects'] = array('Origin.id', 'Origin.origin', 'Name.id', 'Name.name', 'Name.gender', 'Name.meaning', 'Name.origin_id');
$collection = $this->Name->paginate($this->params);
$this->set('objects', $collection['objects']);
$this->set_pagination($collection);