我有一个带有codeIgniter 3.0.4分页库的工作文件管理器。
我正在尝试确保它首先显示目录,然后显示分页中的文件。
目前,codeigniter分页按名称对目录和文件进行排序。
使用codeigniter分页的问题如何确保它首先显示所有目录。然后排序文件。
{{1}}
答案 0 :(得分:0)
解决了我找到了一些其他地方的代码,这些代码使它对我起作用。我现在也用过array_reverse();所有工作到目前为止。
<?php
class Filemanager extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('upload');
$this->load->helper('text');
$this->load->library('pagination');
$this->load->helper('custom');
define('DIR_IMAGE', FCPATH . 'images/');
}
public function index() {
$data['title'] = 'File Manager';
if ($this->uri->segment(3)) {
$this_input_get_directory = $this->uri->segment(2) . '/' . $this->uri->segment(3);
} else {
$this_input_get_directory = $this->uri->segment(2) . '/' . $this->uri->segment(3);
}
if (isset($this_input_get_directory)) {
$directory = rtrim(DIR_IMAGE . 'catalog/' . str_replace(array('../', '..\\', '..'), '', $this_input_get_directory), '/');
} else {
$directory = DIR_IMAGE . 'catalog';
}
// Get directories
$directories = glob($directory . '/' . '*', GLOB_ONLYDIR);
if (!$directories) {
$directories = array();
}
// Get files
$files = array_reverse(glob($directory . '/' . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE));
if (!$files) {
$files = array();
}
// Merge directories and files
$images = array_merge($directories, $files);
$files_limit = 6;
$input_get_per_page = $this->input->get('per_page');
$input_get_per_page += $files_limit;
$config['base_url'] = base_url('filemanager');
$config['total_rows'] = count($images);
$config['per_page'] = $files_limit;
$config['page_query_string'] = TRUE;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$data['images'] = array();
foreach ($images as $file => $value) {
$filename = str_replace(FCPATH . 'images/', '', $value);
$display_name = basename($filename);
if ($file < $input_get_per_page && $file >= $input_get_per_page - $files_limit) {
if (is_dir(DIR_IMAGE . $filename)) {
$data['images'][] = array(
'thumb' => '',
'type' => 'directory',
'path' => $value,
'name' => $display_name,
'href' => site_url('filemanager/' . $display_name)
);
} else if (is_file(DIR_IMAGE . $filename)) {
$data['images'][] = array(
'thumb' => $this->resize($filename),
'type' => 'image',
'path' => $value,
'name' => $display_name
);
}
}
}
$url = '';
if (isset($this_input_get_directory)) {
$pos = strrpos($this_input_get_directory, '/');
if ($pos) {
$url .= '?directory=' . urlencode(substr($this_input_get_directory, 0, $pos));
}
}
$data['parent'] = base_url('filemanager' . $url);
$url = '';
if (isset($this_input_get_directory)) {
$url .= '?directory=' . $this_input_get_directory;
}
$data['refresh'] = base_url('filemanager' . $url);
$this->load->view('template/common/filemanager_view', $data);
}
}