2012-08-23 4 views
0

현재 pyrocms 페이지에 제품 목록이 표시됩니다. 플러그인을 사용하여 db 테이블에서 제품을 가져와 목록으로 표시합니다. 페이지 매김을 사용하려고하지만 사용법 및 시작 위치를 모릅니다. 아무도 자습서를 알고 있거나 약간의 suggstion을 가지고 있습니까?Pyrocms 페이지의 페이지 매기기

+0

왜 이것을 플러그인으로 코딩해야합니까? –

+0

그것은 단지 CodeIgniter이므로, 당신이 좋아하는 것을하십시오! CodeIgniter 문서에서 설명하는대로 URL에서 정보를 가져 와서 페이지 매김 라이브러리에 입력하십시오. –

답변

0

pyrocms는 codeigniter 프레임 워크를 사용합니다.이 코드는 모듈의 경우 완벽하게 작동하지만, 플러그인에서이 코드를 사용해 본 적이 없지만 여전히 시도해 볼 수 있습니다. 사용

$this->load->library('pagination'); 

$config['base_url'] = 'http://example.com/index.php/test/page/'; 
$config['total_rows'] = 200; 
$config['per_page'] = 20; 

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

컨트롤러

에서

로드 매김 라이브러리보기에서이 코드는 페이지 매김 라이브러리를로드하거나 초기화 할 필요가 없습니다 링크

echo $this->pagination->create_links(); 
+0

답장을 보내 주셔서 감사하지만 콘트롤러가 페이지와 플러그인에 전혀 관여하지 않습니다. 모두 –

+0

으로 가야합니다. 그런 다음이 코드를 plugin.php에 넣고 이것을 사용하면 URL을 쉽게 공유 할 수 있습니다. –

+0

감사합니다. . 나는 이것을하는 방법을 발견했다. 플러그인을 만들고 두 가지 방법으로 데이터를 가져 와서 링크를 만들어 페이지에서 호출했습니다. –

1

을 genrate합니다. 보통 codeigniter에서하는 것과 조금 다르며, 여러분이하는 방식을 확실하게 사용할 수 있습니다. codeigniter pagination class

저는 페이지 매김을 위해 이것을 보통합니다. 분명히 컨트롤러 사용이

.... 
    // Create pagination links 
    $total_rows = $this->products_m->count_all_products(); 
    $pagination = create_pagination('products/list', $total_rows); 
    //notice that product/list is your controller/method you want to see pagination there   

    // Using this data, get the relevant results 
    $params = array(
     'limit' => $pagination['limit'] 
    ); 
    $this_page_products = $this->product_m->get_all_products($params); 
    .... 
    //you got to pass $pagination to the view 
    $this->template 
      ->set('pagination', $pagination) 
      ->set('products', $this_page_products) 
      ->build('products/view'); 

을에

, 당신이 당신의 get_all_products 기능을 것 모델에서 products_m 라는 이름의 모델이있을 것이다, 나는 당신이 count_all_products() 기능을 구축 할 수 있습니다 확신 너무

private function get_all_products($params){ 
//your query to get products here 
// use $this->db->limit(); 

// Limit the results based on 1 number or 2 (2nd is offset) 
     if (isset($params['limit']) && is_array($params['limit'])) 
       $this->db->limit($params['limit'][0], $params['limit'][1]); 
     elseif (isset($params['limit'])) 
       $this->db->limit($params['limit']); 
//rest of your query and return 
} 

이제 $products 변수에 foreach의 변수가 있어야하며 페이지 링크를 표시하려면이 줄을보기에 사용하십시오.

<?php echo $pagination['links'];?> 

내 작품에서 이것을 사용하면 도움이되기를 바랍니다.