2013-06-29 2 views
0

codeigniter를 사용하고 있습니다. 내 데이터베이스에서 배열을 검색했습니다. 뷰에 이미지의 현재 번호 (일련 번호)를 전달하여 거기에 표시 할 수 있도록해야합니다.Codeigniter 현재 이미지의 일련 번호를 전달하십시오.

첫 번째 페이지에서 첫 번째 이미지임을 사용자가 알 수 있도록 #1을 전달해야한다고 가정합니다. 그리고 세 번째 이미지 (array[2])를 방문하면 #3이 표시됩니다.

기본적으로 사용자는 next #4#2 previous을 클릭하여 이미지를 살펴보고 페이지의 현재 이미지의 일련 번호를 표시 할 수 있습니다.

array(5) { 
    [0]=> 
    object(stdClass)#21 (6) { 
    ["id"]=> 
    string(2) "17" 
    ["gallery_id"]=> 
    string(1) "5" 
    ["title"]=> 
    string(6) "sample" 
    ["filename"]=> 
    string(12) "n9a67681.jpg" 
    ["description"]=> 
    string(10) "sdhdfhafdj" 
    ["created"]=> 
    string(19) "2013-06-29 08:25:56" 
    } 
    [1]=> 
    object(stdClass)#22 (6) { 
    ["id"]=> 
    string(2) "18" 
    ["gallery_id"]=> 
    string(1) "5" 
    ["title"]=> 
    string(6) "sample" 
    ["filename"]=> 
    string(13) "n9a676811.jpg" 
    ["description"]=> 
    string(10) "sdhdfhafdj" 
    ["created"]=> 
    string(19) "2013-06-29 08:26:28" 
    } 
    [2]=> 
    object(stdClass)#23 (6) { 
    ["id"]=> 
    string(2) "19" 
    ["gallery_id"]=> 
    string(1) "5" 
    ["title"]=> 
    string(6) "sample" 
    ["filename"]=> 
    string(13) "n9a676812.jpg" 
    ["description"]=> 
    string(10) "sdhdfhafdj" 
    ["created"]=> 
    string(19) "2013-06-29 08:27:04" 
    } 
    [3]=> 
    object(stdClass)#24 (6) { 
    ["id"]=> 
    string(2) "20" 
    ["gallery_id"]=> 
    string(1) "5" 
    ["title"]=> 
    string(7) "safdhfh" 
    ["filename"]=> 
    string(35) "tumblr_mfyn3l81ft1qkfae2o1_1280.jpg" 
    ["description"]=> 
    string(4) "dsgd" 
    ["created"]=> 
    string(19) "2013-06-29 08:28:16" 
    } 
    [4]=> 
    object(stdClass)#25 (6) { 
    ["id"]=> 
    string(2) "21" 
    ["gallery_id"]=> 
    string(1) "5" 
    ["title"]=> 
    string(8) "dshfdhsd" 
    ["filename"]=> 
    string(36) "tumblr_mfyn3l81ft1qkfae2o1_12801.jpg" 
    ["description"]=> 
    string(6) "dahadf" 
    ["created"]=> 
    string(19) "2013-06-29 08:29:35" 
    } 
} 
+0

페이지 매김 클래스가 도움이 될 것이라고 생각합니다. http://ellislab.com/codeigniter/user-guide/libraries/pagination.html – sinisake

답변

1

컨트롤러 : 당신이 당신의 이미지 정보와 함께 원하는 뷰 파일에

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

$config['base_url'] = example.com/controller/action/uri_segment; 
$config['total_rows'] = 5; 
$config['per_page'] = 1; 
$config['uri_segment'] = 3; 

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

$position = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 

$data['links'] = $this->pagination->create_links(); 
$data['image'] = your_array[$position]; 

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

넣고는 "$ 링크를 에코"(다음 및 이전 링크를 만들 수), 작업.

관련 문제