每当我点击分页链接时......它显示找不到对象。我没有得到如何将值传递给{index.php / view_expenses / view& per_page = 2}此页面。不介意,如果这样是一个愚蠢的问题,我只是2个月大的PHP和codeigniter.Any帮助将是伟大的:D
这是我的控制器
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);*/
}
这是我的模特
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();
}
答案 0 :(得分:0)
要创建分页HTML,您可以调用create_links()
,然后使用其他数据将其传递给您的视图。这将自动为您生成正确的链接。尝试将其包含在您的控制器中:
$this->data['pagination'] = $this->pagination->create_links();
确保在$this->pagination->initialize($config);
然后在你看来:
echo $pagination;
答案 1 :(得分:0)
模型中的更改:
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;
}
在你的控制器中改变以下行,
$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,
);
您正在加载model
两次我看到,评论第二个。如果您未在视图中加载,为什么使用$result['contents']=$this->emp_expenses_model->getRows($limit,$offset);
?
在您的视图中,请致电<?=$this->pagination->create_links()?>
以查看分页。