Welcome Guest, Not a member yet? Register   Sign In
Change the paginate method
#3

You know better! But now the following code accesses the database 3 times and this is not correct:
PHP Code:
$segment  3
$perPage  10;
$page       = (int)$params[0];
if(!
$page)$page++;
$template 'default'
$model = new CustomerModel();
$validation = \Config\Services::validation();
$validation->setRules([
        
'name'      => ['label' => 'Name''rules' => 'required|max_length[50]'],
        
'email'  => ['label' => 'e-mail''rules' => 'required|max_length[100]'],
$model->where('active','yes');

$total $model->countAllResults(false);

$data   
 
   'table' =>  $model->paginate($perPage,$template,$page),
    
'pagerlinks' =>  $model->pager->Makelinks($page,$perPage,$total,$template.'_full',$segment)
    ]; 

The first call to the COUNT database: $total = $model->countAllResults(false);
The second two calls to the COUNT and * DB: $model->paginate($perPage,$template,$page)
Reply


Messages In This Thread
Change the paginate method - by videoproc - 05-25-2019, 02:10 AM
RE: Change the paginate method - by sv3tli0 - 05-29-2019, 10:22 PM
RE: Change the paginate method - by videoproc - 05-30-2019, 11:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB