Whenever i click on the links of pagination...it shows obeject not found.I am not getting how to pass the value to {index.php/view_expenses/view&per_page=2 } this page.Dont mind if this is a stupid question im just 2month older in php and codeigniter.Any help will be great :D
This is my controller
function view($offset=0)
{
$limit=5;
$this->uri->segment(3);
$this->load->model('emp_expenses_model');
$result['contents']=$this->emp_expenses_model->getRows($limit,$offset);
$result['countRows']=$this->emp_expenses_model->countRows();
$this->load->library('pagination');
$this->load->library('table');
$config=array(
'base_url' => '/index.php/view_expenses/view',
'total_rows' => $this->db->get('emp_expenses')->num_rows($limit,$offset),
'per_page' => $limit,
'uri_segment' => 3,
'num_links' => 1,
);
$this->db->limit(5);
$this->pagination->initialize($config);
$this->load->model('emp_expenses_model');
$this->data['view_expenses'] = $this->emp_expenses_model->get_all();
//var_dump($this->data['pay_list']);die("jk");
$this->data['title'] = 'Payroll System';
$this->data['message'] = $this->session->flashdata('message');
$this->load->library('pagination');
$this->load->view('view_expenses', $this->data);
/*$this->load->view('add_list', $this->data);*/
}
This is my model
function getRows($limit,$offset)
{
$query=$this->db->select('expenses_id,id,dropdown,modeofpayment,amount')
->from('emp_expenses')
->limit($limit,$offset);
$result=$query->get()->result_array();
return $result;
}
function countRows()
{
$query="select count(*) as count from emp_expenses";
$result=$this->db->query($query);
return $result->result_array();
}
To create the pagination HTML, you can to call create_links()
, and then pass this to your view with the other data. This will automatically generate the correct links for you. Try including this in your controller:
$this->data['pagination'] = $this->pagination->create_links();
Make sure you call it after $this->pagination->initialize($config);
Then in your view:
echo $pagination;
Changes in your model:
function countRows(){
//$query="select count(*) as count from emp_expenses";
$result = $this->db->count_all_results('emp_expenses');
//$result=$this->db->query($query);
return $result;
}
In your controller change the follwing lines,
$result['countRows']=$this->emp_expenses_model->countRows();
$this->load->library('pagination');
$this->load->library('table');
$config=array(
'base_url' => '/index.php/view_expenses/view/',
'total_rows' => $result['countRows'],
'per_page' => $limit,
'uri_segment' => 3,
'num_links' => 1,
);
You are loading the model
two times I see, comment the second one. Why are you using $result['contents']=$this->emp_expenses_model->getRows($limit,$offset);
if you are not loading it in view?
In your view call <?=$this->pagination->create_links()?>
to see the pagination.