CodeIgniter Forums
how to make pagination from read folder? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to make pagination from read folder? (/showthread.php?tid=36798)



how to make pagination from read folder? - El Forum - 12-15-2010

[eluser]codingmumet[/eluser]
how to make pagination data from read folder?

Quote: function dir_list($dir)
{
if ($dir[strlen($dir)-1] != '/') $dir .= '/';

if (!is_dir($dir)) return array();

$dir_handle = opendir($dir);
$dir_objects = array();
while ($object = readdir($dir_handle))
if (!in_array($object, array('.','..')))
{
$filename = $dir . $object;
$file_object = array(
'name' => $object,
'size' => filesize($filename),
// 'perm' => permission($filename),
// 'type' => filetype($filename),
'time' => date("d F Y H:iConfused", filemtime($filename))
);
$dir_objects[] = $file_object;

}
return $dir_objects;
}


tq


how to make pagination from read folder? - El Forum - 12-15-2010

[eluser]Madmartigan1[/eluser]
Without getting into how to actually code it, you could use GET parameters or URI segments as your "offset", and then read the array keys of $dir_objects to display the items.

So if we are on files/page/20, you can do something like this:
Code:
$per_page = 10;

$offset = $this->uri->uri_segment(3);

$dir_objects = array_slice($dir_objects, $offset, $per_page);

I would just use standard techniques to create the pagination links, I'm pretty sure the CI pagination class won't help.

Edit: Above code won't work exactly, but should get you on the right track I hope!