Welcome Guest, Not a member yet? Register   Sign In
How can I use a join to paginate the model?
#1
Question 
(This post was last modified: 11-10-2022, 08:48 AM by arslanturk.)

Hello everyone,

I've been using ci4 for a long time. I am very pleased. Thank you.

If I come to my question. Now I have a model and I'm paginating. But I need to join from other tables.

and I want to do this with the model. How can I do ?

Code Example :

PHP Code:
$search_by  $this->request->getget('search_by');
$page      $this->request->getget('page');
$per_page  $this->request->getget('per_page');
$sort_by    $this->request->getget('sort_by');
$sort      $this->request->getget('sort');

if (
$page == ""){$page 1;}
if (
$per_page == ""){$per_page 5;}
if (
$sort_by == ""){$sort_by "id";}
if (
$sort == ""){$sort "desc";}

$where = [
 
'customer_id' => 5,
 
'active' => 1,
 ];

$c  = new customers(); 
$pager = \Config\Services::pager();                
$customers
$c
 
//->join('contact', 'contact.customer_id = customers.id', 'left')
 //->join('address', 'address.customer_id = customers.id', 'left')
 
->where($where)
 ->
orderBy($sort_by$sort)
 ->
paginate($per_page'active_customers'$page);
  

When I activate the //join line on the model, the system gives an error.

I haven't been able to solve this issue for a long time.

Can you write a full sample code based on the example I gave?

Thank you from now.
Reply


Messages In This Thread
How can I use a join to paginate the model? - by arslanturk - 11-10-2022, 08:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB