2012-01-16 5 views
1

私は簡単な検索やAJAXなどを作成するためにcodeigniterを使用しました。ページネーションクラスを統合したいと思います。私はいくつかの例を読んでいます。このライブラリは$this->table->generate($results);のようなものを使用しています。そのエントリ。私はすでに行いましたが、今ページングのそのような方法で、私は大きな問題を抱えています。誰もこの問題で私を助けることができますか?私はCIに見つけることが手掛かりまたは何かを必要とCodeIgniterでページネーションを検索に統合するにはどうすればよいですか?

私は念のために、ここで私のモデル、コントローラとビューを置く

コントローラ

public function searchdescription() 
    { 
    //$keyword = $this->input->post('keyword'); 
    $keyword = $_POST['keyword']; 
    $this->load->model('searchdesc/searchdesc_model'); 
    $data['retorno'] = $this->searchdesc_model->querydb($keyword); 
    $this->load->view('searchdesc/searchresults_view', $data); 
} 

モデル

function querydb($data,$num, $offset) 
    { 

    $queryresult = $this->db->query("select * from data where deleteflag=0 and title like  '%$data%' or text like '%$data%' LIMIT $num, $offset "); 
    return $queryresult->result_array(); 
    } 

ビュー

foreach ($retorno as $val) 
{ 
echo $val['id']; 
echo $val['title']; 
echo $val['text']; 
...here are some forms autocreated in each row that i need to keep making it 
} 
+0

ここをクリックしてください:http://codeigniter.com/user_guide/libraries/pagination.html –

答えて

1
<?php echo $this->table->generate($records); ?> 
<?php echo $this->pagination->create_links(); ?> 

行にボタンを追加するには、この

foreach($records as $row){ 
$row->title = ucwords($row->title); 

$this->table->add_row(
$row->date, 
anchor("main/blog_view/$row->id", $row->title), 
$row->status,  
anchor("main/delete/$row->id", $row->id, array('onClick' => "return confirm('Are you sure you want to delete?')")), 
anchor("main/fill_form/$row->id", $row->id) 
); 
} 
$table = $this->table->generate(); 
echo $table; 
ような何かを:私はテーブルを配置したい場所をここは、ビューで

public function big() 
{ 
    $this->load->library('pagination'); 
    $this->load->library('table'); 

    $config['base_url'] = base_url().'/site/big/'; 
    $where = "bot = '2' OR bot = '0'"; 
    $this->db->where($where); 
    $config['total_rows'] = $this->db->count_all_results('visitors'); 
    $config['per_page'] = 15; 
    //$config['num_links'] = 20; 
    $config['full_tag_open'] = '<div id="pagination">'; 
    $config['full_tag_close'] = '</div>'; 

    $this->pagination->initialize($config);  

    $where = "bot = '2' OR bot = '0'"; 
    $this->db->where($where); 
    $this->db->select('id, ip, date, page, host, agent, spammer, country, total, refer'); 
    $this->db->order_by("date", "DESC"); 
    $data['records'] = $this->db->get('visitors', $config['per_page'], $this->uri->segment(3)); 

    $this->table->set_heading('Id', 'IP', 'Date', 'Page', 'Host', 'Agent', 'Spam', 'Country', 'Total', 'Referer'); 

    $this->db->select_sum('total', 'trips'); 
    $query = $this->db->get('visitors'); 
    $data['trips'] = $query->result(); 

    $this->load->view('site_view', $data);  
} 

(モデルを使用していない)の例であります

もちろんあなたのニーズに合わせて修正します

関連する問題