在最后一页分页codeigniter中创建按钮

时间:2013-08-16 13:59:08

标签: forms codeigniter button pagination

你好,我有问题

我想在我的分页代码中创建按钮在最后一页提交表单

这里是我的代码:

控制器:

    function index() {
/* pagination config */
        $this->load->library('pagination');
        $config['base_url'] = site_url('dcm/index');
        $config['per_page'] = 6;
        $config['num_link'] = 5;
        $config['next_link'] = 'Next';
        $config['prev_link'] = 'Prev' ;
        $config['total_rows'] = $this->db->get('soal')->num_rows();

/* this my form still have problem but I have different post for this one */
/* if you have any Idea for this please check my Question */
        $data['form_action'] = site_url('dcm/index');     
        $jawab = $this->input->post('jawab');
        $id_soal = $this->input->post('id_soal');
        $this->dcm_model->inputJawab();
        /*  */


/* pagination setting */
        $this->pagination->initialize($config);
        $data['query'] = $this->db->get('soal', $config['per_page'], $this->uri->segment(3));
        $data['link'] = $this->pagination->create_links();
        $this->load->view('dcm/soal', $data);
}

在视图中:

<form action="<?php echo $form_action; ?>">
<?php  foreach($query->result() as $row) { ?>
<?php echo $row->id_soal . '. ' . $row->soal; ?>
<input type="checkbox" checked="checked"  value="<?=$row->id_soal;?>" name="jawab[]" />
<?php } ?>
<?php echo $link; ?>
</form>
<input align="center" type="submit" value="selesai" />

1 个答案:

答案 0 :(得分:2)

您可以使用以下代码检查您是否在最后一页:

if($this->pagination->cur_page >= 
    ceil($this->pagination->total_rows / $this->pagination->per_page))
{
    $isLastPage = true;
}
else
{
    $isLastPage = false;
}

您可以将$isLastPage变量传递给您的视图。