マイコントローラー:Codeigniter:検索方法はポスト方法で制限されていませんか?
public function search()
{
$data['category_name'] = $this->model_products->dis_category();
$this->load->view('layout/header', $data);
$keyword = ''; // default when no term in session or POST
if ($this->input->post('search'))
{
// use the term from POST and set it to session
$keyword = $this->input->post('search');
$this->session->set_userdata('keyword', $keyword);
}
elseif ($this->session->userdata('keyword'))
{
// if term is not in POST use existing term from session
$keyword = $this->session->userdata('keyword');
}
$data['otherproduct'] = $this->model_products->other_prodects();
$data['otherproduct2'] = $this->model_products->other_prodects2();
//Pagination init
$config['base_url'] = base_url().'search/';
$config['total_rows'] = $this->model_products->num_rows($keyword);
$config['per_page'] = 10;
$config['uri_segment'] = 2;
$config['num_links'] = 2;
//custom pigination
$config['full_tag_open'] = '<ul class="tsc_pagination tsc_paginationA tsc_paginationA01">';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = 'Prev';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="current"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$data['search'] = $this->model_products->SearchResult($config['per_page'],$this->uri->segment(2,0),$keyword);
$this->load->vars($data);
$this->load->view('layout/resault', $data);
$this->load->view('layout/footer');
}
マイモデル:
function SearchResult($perPage,$uri,$keyword)
{
$this->db->select('*');
$this->db->like('pro_part',$keyword);
$this->db->or_like('pro_description',$keyword);
$this->db->or_like('pro_name',$keyword);
$this->db->order_by('pro_part','asc');
$getData = $this->db->get('products', $perPage, $uri);
return $getData->result_array();
}
function num_rows($keyword){
$this->db->select('*');
$this->db->where_in("'pro_part' like '%$keyword'");
$this->db->or_where_in("'pro_name' like '%$keyword'");
$query = $this->db->get('products');
return $query->num_rows();
}
マイビュー:
Featured Products </span></h2>--> Results for "session->userdata('word') ;?>"
<?php if(count($search) > 0):?> <?php foreach ($search as $row) :?> <div class="span13 product"> <div> <figure> <?php if(!empty($row['pro_image'])): ?> <a href="<?= site_url("view")."?productdetail=".$row['pro_id'];?>"><img
src="template/images/products/" alt="image" />
<?php else :?> <img alt="image" src="http://placehold.it/50x35"> </a> <?php endif;?> </figure> <div class="detail"> <span>$<?php echo $row['pro_price'];?></span> <h4><?php echo $row['pro_part'];?></h4> <h4><?php echo $row['pro_name'];?></h4> <div class="icon"> <a href="<?=site_url("add-to-cart")."/".$row['pro_id'];?>" class="one
tooltip" title="Add to cart">
</div> </div> </div> </div> <?php endforeach;?> <div class="span12"> <div class="pagination clearfix"> <!--<p>Items 1 to 9 of 12 total</p>--> <ul class="clearfix"> <?php echo $this->pagination->create_links(); ?> </ul> </div> </div> <?php else: ?> <div class="span12"> We did not find results for"<?php echo $this->session->userdata('word') ;?>" <div class="search_other"> <span>Other Products</span> </div> <div class="container"> <div class="row"> <section class="responsive slider"> <?php foreach($otherproduct as $row): ?> <div> <div class="span13 product"> <figure> <?php if(!empty($row->pro_image)): ?> <a href="<?= site_url("view")."?productdetail=".$row->pro_id;?>"><img
src="template/images/products/pro_image ;?>" alt="image" />
<?php else :?> <img alt="image" src="http://placehold.it/50x35"> </a> <?php endif;?> </figure> <div class="detail"> <span>$<?php echo $row->pro_price;?></span> <h4><?php echo $row->pro_part;?></h4> <h4><?php echo $row->pro_name;?></h4> <div class="icon"> <a href="<?=site_url("add-to-cart")."/".$row->pro_id;?>" class="one
tooltip" title="Add to cart">
</div> </div> </div> </div> <?php endforeach;?> <?php foreach($otherproduct2 as $row): ?> <div> <div class="span13 product"> <figure> <?php if(!empty($row->pro_image)): ?> <a href="<?= site_url("view")."?productdetail=".$row->pro_id;?>"><img
src="template/images/products/pro_image ;?>" alt="image" />
<?php else :?> <img alt="image" src="http://placehold.it/50x35"> </a> <?php endif;?> </figure> <div class="detail"> <span>$<?php echo $row->pro_price;?></span> <h4><?php echo $row->pro_part;?></h4> <h4><?php echo $row->pro_name;?></h4> <div class="icon"> <a href="<?=site_url("add-to-cart")."/".$row->pro_id;?>" class="one
tooltip" title="Add to cart">
</div> </div> </div> </div> <?php endforeach;?> <div> </section> </div> </div> </div> <?php endif; ?> </div> </div> </div>
私の問題は、結果改ページ数、データベース内のすべての私の行は、POSTメソッドによる制限ではありません。
に条件
を使用していないので、あなたのケースではnullをなり、アレイのために使用されているwhere_inにwhere_inモデル私たちが行くことを期待してください。そこにはいくつかの基本的な誤りがあります。私が考えている主なものは、バッククォートの代わりにシングルクォートされた識別子です。 –
あなたの現在の問題は何ですか?あなたは '$ config ['per_page'] = 10;を指定しましたが、動作しません。 –
これを参照してください - > http://www.iprogrammerindia.in/pagination-search-and-field-sorting-in-codeigniter/ –