我想使用codeigniter创建一个分页。问题是我无法根据下拉选项列表中的值显示我的记录.Plz帮助。
这是我的控制器代码:
public function index($offset = 0)
{
$data['title'] = "Basic CRUD Function With Codeigniter";
if (!empty($post['limit'])) {
$limit = $this->input->post('limit');
}
else{
$limit = 1;
}
$offset = $this->uri->segment(3);
$records = $this->crud_mdl->get_paged_list($limit, $offset);
$config['base_url'] = base_url().'/crud/index/';
$config['total_rows'] = $this->crud_mdl->count_all();
$config['per_page'] = $limit;
$this->pagination->initialize($config);
$data['limit'] = $this->input->post('limit');
$data['pagination'] = $this->pagination->create_links();
$this->load->library('table');
$this->table->set_heading('ID','NAME','E-MAIL','PHONE','ACTION');
foreach ($records as $record) {
$this->table->add_row($record->id, $record->name, $record->email, $record->phone,
anchor('crud/viewCrud/'.$record->id,'view').' '.anchor('crud/editCrud/'.$record->id,'edit').' '.anchor('crud/delete/'.$record->id,'delete')
);
}
$data['table'] = $this->table->generate();
$this->load->view('crudlist',$data);
}
这是我的模特:
public function count_all()
{
return $this->db->count_all('test');
}
public function get_all_data()
{
return $this->db->get('test')->result();
}
public function get_paged_list($limit, $offset)
{
return $this->db->get('test', $limit, $offset)->result();
}
这是我的观点:
<div>
<h1>Simple CRUD Application</h1>
<div><?php echo $pagination;?></div>
<?php echo form_open('crud/index');?>
<select name="limit" onchange="form.submit()">
<option value="1" <?php if ($limit == 1){ echo "selected='selected'";} ?>>1</option>
<option value="2" <?php if ($limit == 2){ echo "selected='selected'";}?> >2</option>
<option value="4" <?php if ($limit == 4){ echo "selected='selected'";}?> >4</option>
</select>
<?php echo form_close();?>
<div><?php echo $table; ?></div>
<br />
<?php echo anchor('crud/addCrud','Add CRUD'); ?>
</div>
答案 0 :(得分:0)
$post
未定义,可能您的意思是$_POST
,也可以用作$this->input->post()
。所以替换:
if (!empty($post['limit'])) {
应该是:
if (!empty($this->input->post('limit'))) {