私は codeigniter フレームワークが初めてで、検索フィルターでページネーションを行おうとしています。
私はこれ(ただし答えはありません)やこれもチェックされた答えがないなどの答えに出くわしたので、それが正しい方法であるかどうかわからず、さらに混乱しています。
私が持っているのは、デフォルトで、ページネーションを使用してテーブルのすべての結果がページに表示されることです。
今、私は立ち往生していて、かなり混乱しているので、明らかな間違いがいくつかある場合はご容赦ください.
ここで私がやろうとしているのは、ユーザーがドロップダウンボックスで値を選択して送信したときです。たとえば、顧客 A を送信するとCustomer A
、列customer
のみを含む行が期待されます。
ただし、送信した後、ヘッダーとフッターのないプレーンテキスト (個別のビュー) で、すべての結果とさらに悪い結果が得られます。それは私がそれらを呼び出さなかったからだと理解していますが、それでもそれらCustomer A
のみを表示しません。
フォームの送信後に、フォームから取得した値に従ってページネーション クエリを実行し、選択した行を表示する簡単なソリューションを見つけようとしています。2 つのリンク以外が見つからないように見えるので、正しい方法でフィルタリングしているかどうかわかりません。
意見
<form method="POST" action='<?php echo base_url("index.php/Home/load_lot_table")?>' class="form-inline">
<select id="cust_drop_down" name="cust_drop_down" class="form-control input-mini">
<option value="all">All</option>
<option value="custA">Customer A</option>
<option value="custB">Customer B</option>
</select>
<input type="submit" class="btn btn-primary purple_button" value="Search">
</form>
コントローラ
public function on_hold_lot() // Default function to display result
{
$data['title'] = 'Search System';
$this->load->view('templates/normal_header', $data);
$this->populate_customer_dropdown(); // private
$this->load_lot_table(); // public
$this->load->view('templates/legend_footer', $data);
}
public function load_lot_table() // Main pagination function
{
if(isset($this->input->post))
{
$search = array(
'customer' => $this->input->post('cust_drop_down')
);
}
else
{
$search = array(
'customer' => 'all',
'stage' => 'all',
'lot_status' => 'all'
);
}
$config = array();
$config['base_url'] = base_url()."index.php/Home/on_hold_lot";
$config['total_rows'] = $this->home_model->record_count();
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$results = $this->home_model->fetch_lots($config['per_page'], $page, $search);
$data['disp_rows'] = $results;
$data['links'] = $this->pagination->create_links();
return $this->load->view('home/lot_disposition', $data);
}
モデル
public function record_count()
{
return $this->db->count_all('disp_dummy');
}
public function fetch_lots($limit, $start, $search = null)
{
$this->db->limit($limit, $start);
if($search != null && $search['customer'] != 'all')
{
$this->db->where('customer', $search['customer']);
}
$query = $this->db->get('disp_dummy');
if($query->num_rows() > 0)
{
foreach($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
else
{
return false;
}
}