Hello everyone, I am new to Codeigniter 4... And I'am trying to figure this pagination out...
I've got this function, and it works as it should:
PHP Code:
public function butikk()
{
$model = new ButikkModel();
$data = [
'ovner' => $model->paginate(6),
'pager' => $model->pager
];
echo view('templates/v2/header');
echo view('pages/butikk', $data);
echo view('templates/v2/footer');
}
But this grabs everything from my table. I've different types of content in that table, differences with 1,2 or 3 as value in a column named type.
My model:
PHP Code:
public function getOvner($id = false, $type = 1)
{
if ($slug === false) {
$query = $this->db->query("SELECT * FROM ovner WHERE type='$type' ORDER BY created_at DESC");
$results = $query->getResultArray();
return $results;
}
return $this->asArray()
->where(['id' => $id])
->first();
}
Here I am running my query, and this works just fine without the pagination part.
So what I discovered was, when using "->pagination" in my controller, it totally ignores what I've got in my model.
This is obviously because it never runs this function.
How can I implement this? So it only grabs lets say type 1.
Thanks in advance!
Regards Stian.