0

我正在使用代码点火器。我从我的数据库中检索了一个数组。我需要将图像的当前编号(序列号)传递到视图中,以便我可以在其中显示它。

比如说,在第一页中,我需要传递#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"
  }
}
4

1 回答 1

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);

放入您的视图文件“echo $links”(创建下一个和上一个链接),并根据需要使用图像信息。

于 2013-08-27T20:55:32.133 回答