What do I want to do
I want to list data that is pulled from the database with a certain condition.
What do I have and what does it do
I have a function that calls the data. When I print_r the data, it throws the correct stuff, so the query is executing directly. However, the display isn’t working. It shows all the data in the database.
Here is my function:
public function myfunction() {
$adminExtensions = $this->AdminExtension->find('all',
array(
'conditions' => array('location_id'=>'3')
)
);
//print_r($adminExtensions);
$this->set('adminExtensions', $this->paginate());
}
What is the problem
The problem, as stated, is that it doesn’t list just the records with location_id == 3. It lists everything.
I have narrowed it down to the last line of the function, but I can’t seem to get the right code in there.
My display file (myfunction.ctp) is a basic baked cakePHP index file.
What am I doing wrong?
The code you currently have calls two different
findoperations.$this->AdminExtension->find()will return an array with all theAdminExtensionswith alocation_idof 3. The second$this->paginate()call just returns all possible results suitable for pagination in the view.If you want to filter the paginated results you have to either configure the
$paginatevariable in the Controller or do it directly before you call$this->paginate.This will adjust pagination for all
$this->paginatecalls in the controller.To do it for only one paginate call: