Welcome Guest, Not a member yet? Register   Sign In
[ERROR] Pagination initialize() in Codeigniter 2.10
#1

[eluser]Fandy[/eluser]
Hy, masters
I have problem when i try use Pagination library. I use Codeigniter latest version 2.1.0.
And i get following error :

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Action::$pagination
Filename: bukutamu/action.php
Line Number: 56


( ! ) Fatal error: Call to a member function initialize() on a non-object in C:\wamp\www\codeigniter\application\controllers\bukutamu\action.php on line 56


Here is my code in Model and Controller
Model : bukutamu_model.php
Code:
....
function select_limit($limit = array())
  {
   if($limit == NULL)
   {
    return $this->db->get('tbl_bukutamu')->result();
   }
   else
   {
    return $this->db->limit($limit['per_page'], $limit['offset'])->get('tbl_bukutamu')->result();
   }
  }
...


Controller : bukutamu.php
Code:
....
function view()
{
  $data['title'] = 'Buku Tamu';
  
  // tentukan jumlah data per halaman
  $perpage = 3;
  $this->load->library('pagination');

  // Konfigurasi Pagination
  $config['base_url'] = base_url().'bukutamu/action/view/';
  $config['total_rows'] = count($this->bukutamu_model->select_limit());
  $config['per_page'] = $perpage;
  
  $this->pagination->initialize($config);
  $data['bukutamu_list'] = $this->bukutamu_model->select_limit(array('per_page'=>$perpage, 'offset'=>$offset));

  $this->load->view('bukutamu/list_bukutamu_view', $data);
}
....

Please help me,
Thanks before, masters..
#2

[eluser]Stefan Hueg[/eluser]
First of all, here is an optimization:

Code:
function select_limit($limit = array())
{
if($limit == NULL)
{
  return $this->db->count_all('tbl_bukutamu');
}
else
{
  return $this->db->limit($limit['per_page'], $limit['offset'])->get('tbl_bukutamu')->num_rows;
}
}

and

Code:
...
$config['total_rows'] = $this->bukutamu_model->select_limit();
...

Second, could you enable logging in your config.php, set the log level to 4 and see what your log tells? Whether the pagination class is loaded properly?

If so, you should see an entry like "Pagination Class Initialized".
#3

[eluser]Fandy[/eluser]
Hay Stefan, thank you for your fast response.
I have changed, but still error. And i enable the logging to level 4, and i get this report.
I think pagination already initialized.

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

DEBUG - 2012-04-30 15:04:45 --> Config Class Initialized
DEBUG - 2012-04-30 15:04:45 --> Hooks Class Initialized
DEBUG - 2012-04-30 15:04:45 --> Utf8 Class Initialized
DEBUG - 2012-04-30 15:04:45 --> UTF-8 Support Enabled
DEBUG - 2012-04-30 15:04:45 --> URI Class Initialized
DEBUG - 2012-04-30 15:04:45 --> Router Class Initialized
DEBUG - 2012-04-30 15:04:46 --> Output Class Initialized
DEBUG - 2012-04-30 15:04:46 --> Security Class Initialized
DEBUG - 2012-04-30 15:04:46 --> Input Class Initialized
DEBUG - 2012-04-30 15:04:46 --> Global POST and COOKIE data sanitized
DEBUG - 2012-04-30 15:04:46 --> Language Class Initialized
DEBUG - 2012-04-30 15:04:46 --> Loader Class Initialized
DEBUG - 2012-04-30 15:04:46 --> Helper loaded: url_helper
DEBUG - 2012-04-30 15:04:46 --> Helper loaded: form_helper
DEBUG - 2012-04-30 15:04:46 --> Database Driver Class Initialized
DEBUG - 2012-04-30 15:04:46 --> Controller Class Initialized
DEBUG - 2012-04-30 15:04:46 --> File loaded: application/views/bukutamu/main_view.php
DEBUG - 2012-04-30 15:04:46 --> Final output sent to browser
DEBUG - 2012-04-30 15:04:46 --> Total execution time: 0.7422
DEBUG - 2012-04-30 15:04:49 --> Config Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Hooks Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Utf8 Class Initialized
DEBUG - 2012-04-30 15:04:49 --> UTF-8 Support Enabled
DEBUG - 2012-04-30 15:04:49 --> URI Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Router Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Output Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Security Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Input Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Global POST and COOKIE data sanitized
DEBUG - 2012-04-30 15:04:49 --> Language Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Loader Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Helper loaded: url_helper
DEBUG - 2012-04-30 15:04:49 --> Helper loaded: form_helper
DEBUG - 2012-04-30 15:04:49 --> Database Driver Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Controller Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Model Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Database Driver Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Controller Class Initialized
DEBUG - 2012-04-30 15:04:49 --> Pagination Class Initialized
ERROR - 2012-04-30 15:04:49 --> Severity: Notice  --> Undefined property: Action::$pagination C:\wamp\www\codeigniter\application\controllers\bukutamu\action.php 56

I attach my code model,view and controller below.
SOURCE

Thanks for your support, Smile
#4

[eluser]Fandy[/eluser]
Anyone can help me? Sad
#5

[eluser]Stefan Hueg[/eluser]
Could you change the following lines:

bukutamu_model.php

Code:
function select_limit($limit = array())
  {
   if(empty($limit))
   {
    return $this->db->count_all('tbl_bukutamu');
   }
   else
   {
    return $this->db->limit($limit['per_page'], $limit['offset'])->get('tbl_bukutamu')->num_rows();
   }
  }

action.php
Code:
function view()
{
  $data['title'] = 'Buku Tamu';
  
  // tentukan jumlah data per halaman
  $perpage = 3;
  $this->load->library('pagination');

  // Konfigurasi Pagination
  $config['base_url'] = base_url().'bukutamu/action/view/';
  $config['total_rows'] = $this->bukutamu_model->select_limit();
  $config['per_page'] = $perpage;
  
  $this->pagination->initialize($config);
  $data['bukutamu_list'] = $this->bukutamu_model->select_limit(array('per_page'=>$perpage, 'offset'=>$offset));

  $this->load->view('bukutamu/list_bukutamu_view', $data);
}

and try it again?

If this even does not work, could you upload your whole project?
#6

[eluser]InsiteFX[/eluser]
total_rows is how many rows in your database table!
limit is how many rows you want to return at once!

Code:
$cnt = $this->db->count_all('table_name');
$config['total_rows'] = $cnt;

// in your model method.
$this->db->limit(10);
// or pass it into the method.
$limit = 10;
$query = $this->db->get_where('table_name', array('id' => $id), $limit, $offset);




Theme © iAndrew 2016 - Forum software by © MyBB