Custom Pagination Page Count Message - codeigniter

On my controller I am trying to be able to display a message where it counts from 1 "Your On Page 1" etc
How ever it does not start of at 1 it starts at 0 "Your On Page 0"
$message = '';
$message .= '<p>' . sprintf('Your on page %d', ($config['total_rows']) ? (($start - 1) * $config['per_page']) + 1 : 0) . '</p>';
$message .= '<p>Total ( Pages ' . ceil($config['total_rows'] / $config['per_page']) . ' )</p>';
$data['total'] = $message;
Question: How can I make sure that it can count from 1 instead of 0 in message with out effecting the main pagination on controller
Controller
<?php
class Forum extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->model('catalog/forum/forum_model');
$this->load->library('pagination');
}
public function category() {
$this->document->set_title('Forums');
$category_id = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
if ($this->input->get('order')) {
$order = $this->input->get('order');
} else {
$order = 'asc';
}
if ($this->input->get('sort')) {
$sort = $this->input->get('sort');
} else {
$sort = 'message';
}
$url = '';
if ($this->input->get('sort')) {
$url .= '?sort=' . $this->input->get('sort');
}
if ($this->input->get('order')) {
$url .= '&order=' . $this->input->get('order');
}
$config["base_url"] = base_url('forum/category') .'/'. $category_id .'/';
$config["total_rows"] = $this->forum_model->total_category($category_id);
$config["per_page"] = 1;
$config['page_query_string'] = TRUE;
$config['reuse_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['pagination'] = $this->pagination->create_links();
$start = ($this->input->get('per_page')) ? $this->input->get('per_page') : '';
$filter_data = array(
'limit' => $config["per_page"],
'start' => $start,
'category_id' => $category_id,
'sort' => ($this->input->get('sort')) ? $this->input->get('sort') : 'message',
'order' => ($this->input->get('order')) ? $this->input->get('order') : 'asc'
);
$data['threads'] = array();
$results = $this->forum_model->get_threads_for_forum($filter_data);
foreach ($results as $result) {
$data['threads'][] = array(
'thread_id' => $result['thread_id'],
'user_id' => $result['user_id'],
'username' => $result['username'],
'subject' => $result['subject'],
'link' => site_url('thread') . '-' . $result['thread_id'],
'total' => $this->forum_model->total_threads($result['thread_id']),
'date_created' => date('d-m-Y', strtotime($result['date_created'])),
'user_link' => site_url('user') . '-' . $result['user_id']
);
}
$data['back'] = site_url('forum');
$data['newthread'] = site_url('newthread') . '?fid=' . $category_id;
$url = '';
if ($order == 'asc') {
$url .= '&order=desc';
} else {
$url .= '&order=asc';
}
if ($this->input->get('per_page')) {
$url .= '&per_page=' . $this->input->get('per_page');
}
$data['thread_message'] = site_url('forum/category') .'/'. $category_id .'/'. '?sort=message' . $url;
$data['date_created'] = site_url('forum/category') .'/'. $category_id .'/'. '?sort=date_created' . $url;
$data['sort'] = $sort;
$data['order'] = $order;
$total_threads = $this->forum_model->get_total_threads_for_category($category_id);
$message = '';
$message .= '<p>' . sprintf('Your on page %d', ($config['total_rows']) ? (($start - 1) * $config['per_page']) + 1 : 0) . '</p>';
$message .= '<p>Total ( Pages ' . ceil($config['total_rows'] / $config['per_page']) . ' )</p>';
$data['total'] = $message;
$data['header'] = Modules::run('catalog/common/header/index');
$data['footer'] = Modules::run('catalog/common/footer/index');
$data['menu'] = Modules::run('catalog/common/menu/index');
$this->load->view('default/template/forum/forum_thread_view', $data);
}
}

It ended up being a simple fix had brain fart should of picked it up straight away.
I changed
(($start - 1) * $config['per_page']) + 1 : 0)
To
(($start - 0) * $config['per_page']) + 1 : 0)

Related

Magento 2 get filter list

I have Magento 2.4.3
I want to get filter list because i want to print price range list in to onother my section of site. (TopMenu.php)
I tried:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$stateFilter = $objectManager->create('\Magento\Catalog\Model\Layer\FilterList');
$selectedFilters = $stateFilter->getFilters();
foreach($selectedFilters as $filter){
$html .= $filter->getName();
$html .= $filter->getLabel();
}
But i get this error:
Cannot instantiate interface Magento\Catalog\Model\Layer\FilterableAttributeListInterface
How can I get what I want?
I found this solution:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$filterableAttributes = $objectManager->getInstance()->get(\Magento\Catalog\Model\Layer\Category\FilterableAttributeList::class);
$layerResolver = $objectManager->getInstance()->get(\Magento\Catalog\Model\Layer\Resolver::class);
$filterList = $objectManager->getInstance()->create(
\Magento\Catalog\Model\Layer\FilterList::class,
[
'filterableAttributes' => $filterableAttributes
]
);
$layer = $layerResolver->get();
$filters = $filterList->getFilters($layer);
$maxPrice = $layer->getProductCollection()->getMaxPrice();
$minPrice = $layer->getProductCollection()->getMinPrice();
$i = 0;
$filterAttrs = [];
$html .= '<ul>';
foreach($filters as $filter)
{
$values = [];
$attr_code = (string)$filter->getRequestVar();
$attr_label = (string)$filter->getName();
if(strtolower($filter->getName())=='price')
{
$html .= (string)$filter->getName();
$items = $filter->getItems();
foreach($items as $item)
{
$html .= '<li>';
$html .= '<a href="/onepage/?price='.$item->getValue().'">';
$html .=$item->getLabel();
$html .= '</a>';
$html .= '</li>';
}
}
}
$html .= '</ul>';

Codeigniter Perpage Link Not Showing First In URL Pagination links

I am making my table head links sortable and orderable how ever my per_page does not show up first
http://localhost/project-1/forum/category/1/&order=asc?per_page=1
It should show like
http://localhost/codeigniter/forum/category/1/?per_page=1&order=asc
Question when I click on the pagination links if the have been order or sorted how can I make sure that when I click on a pagination link even though has been order/sorted will still allways show ?per_page first in url.
$url = '';
if ($this->input->get('sort')) {
$url .= '&sort=' . $this->input->get('sort');
}
if ($this->input->get('order')) {
$url .= '&order=' . $this->input->get('order');
}
$config["base_url"] = base_url('forum/category') .'/'. $category_id .'/'. $url;
Controller
<?php
class Forum extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->model('catalog/forum/forum_model');
$this->load->library('pagination');
}
public function category() {
$this->document->set_title('Forums');
$category_id = $this->uri->segment(3);
if ($this->input->get('sort')) {
$sort = $this->input->get('sort');
} else {
$sort = 'message';
}
if ($this->input->get('order')) {
$order = $this->input->get('order');
} else {
$order = 'asc';
}
$url = '';
if ($this->input->get('per_page')) {
$url .= '?per_page=' . $this->input->get('per_page');
}
if ($this->input->get('sort')) {
$url .= '&sort=' . $this->input->get('sort');
}
if ($this->input->get('order')) {
$url .= '&order=' . $this->input->get('order');
}
$config["base_url"] = base_url('forum/category') .'/'. $category_id .'/'. $url;
$config["total_rows"] = $this->forum_model->total_category($category_id);
$config["per_page"] = 1;
$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);
$start = ($this->input->get('per_page')) ? $this->input->get('per_page') : '';
$filter_data = array(
'limit' => $config["per_page"],
'start' => $start,
'category_id' => $category_id,
'sort' => $sort,
'order' => $this->input->get('order')
);
$data['threads'] = array();
$results = $this->forum_model->get_threads_for_forum($filter_data);
foreach ($results as $result) {
$data['threads'][] = array(
'thread_id' => $result['thread_id'],
'user_id' => $result['user_id'],
'username' => $result['username'],
'subject' => $result['subject'],
'link' => site_url('thread') . '-' . $result['thread_id'],
'total' => $this->forum_model->total_threads($result['thread_id']),
'date_created' => date('d-m-Y', strtotime($result['date_created'])),
'user_link' => site_url('user') . '-' . $result['user_id']
);
}
$data['header'] = Modules::run('catalog/common/header/index');
$data['footer'] = Modules::run('catalog/common/footer/index');
$data['menu'] = Modules::run('catalog/common/menu/index');
$data['pagination'] = $this->pagination->create_links();
$data['back'] = site_url('forum');
$data['thread'] = site_url('newthread') . '?fid=' . $category_id;
$url = '';
if ($order == 'asc') {
$url .= '?order=desc';
} else {
$url .= '?order=asc';
}
$data['message'] = site_url('forum/category') .'/'. $category_id .'/'. $url;
$data['sort'] = $sort;
$data['order'] = '';
$this->load->view('default/template/forum/forum_thread_view', $data);
}
}
Set your default category id if url does not contain:
if ($this->uri->segment(3) == 'null') {
$category_id = 1; //set default for null
} else {
$category_id = $this->uri->segment(3);
}
Edit your config['base_url'] and add set $config['suffix'] if $_GET is not
empty.
New Pagination config:
$config["base_url"] = base_url('forum/category'); //no need custom category id
if (count($_GET) > 0)
$config['suffix']='?'.http_build_query($_GET,'',"&");//to encode requested data
$config["per_page"] = 1;
$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>";
I don't see any:
$config[‘reuse_query_string’] = TRUE;
This will allow to use mixed type of urls. This was not possible before CI 3.0.

Codeigniter Pagination 3.0.4 Sort Directories And Files

I have a working file manager with codeIgniter 3.0.4 pagination library.
I am trying to make sure it displays the directory's first and then files in the pagination.
Currently the codeigniter pagination sorts the directories and files all by name.
Question with codeigniter pagination how can I make sure it all ways displays the directories first. Then sorts out the files.
<?php
class Filemanager extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('upload');
$this->load->helper('text');
$this->load->library('pagination');
}
public function index($results = NULL) {
$data['title'] = 'File Manager';
$this_input_get_directory = $this->input->get('directory');
if (isset($this_input_get_directory)) {
$directory = scandir(FCPATH . 'images/catalog/' . $this_input_get_directory . '/', 1);
} else {
$directory = scandir(FCPATH . 'images/catalog/', 1);
}
$files = array_diff($directory, array('.', '..'));
$files_limit = 3;
$input_get_per_page = $this->uri->segment(2);
$input_get_per_page += $files_limit;
$config['base_url'] = base_url('filemanager');
$config['total_rows'] = count($files);
$config['per_page'] = $files_limit;
$config['uri_segment'] = 2;
$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 ($files as $file => $value) {
$url = '';
if (isset($this_input_get_directory)) {
$url .= $this_input_get_directory . '/';
} else {
$url .= '';
}
if ($file < $input_get_per_page && $file >= $input_get_per_page - $files_limit) {
if (is_dir(FCPATH . 'images/catalog/' . $value)) {
$data['images'][] = array(
'thumb' => '',
'type' => 'directory',
'href' => site_url('filemanager') . '?directory='. $url . $value,
'name' => $value
);
} elseif (is_file(FCPATH . 'images/catalog/' . $url . $value)) {
$data['images'][] = array(
'thumb' => $this->resize($value, 100, 100),
'type' => 'image',
'name' => $value
);
}
}
}
$this->load->view('template/common/filemanager_view', $data);
}
}
Solved I have found some code from some where else that made it work for me. I have also used now array_reverse(); all working so far.
<?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);
}
}

Codeigniter pagination displays extra num links

When I search for a pages in my categories it displays the result of what pages are in that category.
For testing I have set the limit per page to 1 on my search_for
function.
Question/Problem: If there a only 2 pages that show up in result for some reason the pagination links display 5 links where it should only display 2 pagination links.
functions for model are on controller for testing.
I think the problem lies where the db->like and db->or_like in model. Why does it display 5 pagination links when should only display 2 if only 2 results found.
Controller
<?php
class Category_search extends Catalog_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$data['title'] = "Search Category";
$data['categories'] = array();
$results = $this->get_categories();
foreach ($results as $result) {
$data['categories'][] = array(
'category_id' => $result['category_id'],
'name' => $result['name']
);
}
$this->load->library('form_validation');
$this->form_validation->set_rules('page', 'Category');
$this->form_validation->set_rules('name', 'Name');
if ($this->form_validation->run() == FALSE) {
$this->load->view('theme/default/template/pages/search_category_view', $data);
} else {
redirect('pages/category_search/search_for' . '/' . $this->input->post('category'));
}
}
public function search_for($offset = NULL) {
$data['title'] = "Caregory Results";
$data['heading_title'] = "Search" .' - '. $this->get_category_name($this->uri->segment(4));
$data['pages'] = array();
$this->load->library('pagination');
$limit = 1;
$config['base_url'] = base_url('pages/category_search/search_for') .'/'. $this->uri->segment(4);
$config['total_rows'] = $this->get_total_pages();
$config['per_page'] = $limit;
$config['use_page_numbers'] = TRUE;
$config['uri_segment'] = 5;
$config['num_links'] = "16";
$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);
$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
$results = $this->get_pages_within($config['per_page'], $page);
$this->load->model('catalog/tool/model_tool_image');
foreach ($results as $result) {
$data['pages'][] = array(
'category_id' => $result['category_id'],
'parent_id' => $result['parent_id'],
'name' => $result['name'],
'description' => $result['description'],
'image' => $this->model_tool_image->resize($result['image'], 280, 200)
);
}
$data['pagination'] = $this->pagination->create_links();
$this->load->view('theme/default/template/pages/search_category_search_for_view', $data);
}
// Todo move model functions to new model file when complete
public function get_categories() {
$this->db->select('*');
$this->db->from($this->db->dbprefix . 'category c', 'LEFT');
$this->db->join($this->db->dbprefix . 'category_description cd', 'cd.category_id = c.category_id', 'LEFT');
$query = $this->db->get();
return $query->result_array();
}
public function get_pages_within($limit, $offset) {
$this->db->select('*');
$this->db->from($this->db->dbprefix . 'page_to_category p2c', 'LEFT');
$this->db->join($this->db->dbprefix . 'page p', 'p.page_id = p2c.page_id', 'LEFT');
$this->db->join($this->db->dbprefix . 'page_description pd', 'pd.page_id = p2c.page_id', 'LEFT');
$this->db->like('p2c.parent_id', (int)$this->uri->segment(4));
$this->db->or_like('p2c.category_id', (int)$this->uri->segment(4));
$this->db->limit($limit, $offset);
$query = $this->db->get();
return $query->result_array();
}
public function get_total_pages() {
return $this->db->count_all($this->db->dbprefix . 'page');
}
public function get_category_name($category_id = 0) {
$this->db->where('category_id', (int)$category_id);
$query = $this->db->get($this->db->dbprefix . 'category_description');
if ($query->num_rows() > 0) {
$row = $query->row();
return $row->name;
} else {
return FALSE;
}
}
}
I suppose 5 is all the table rows with no where/like filter and it probably come from this function that count everything:
public function get_total_pages() {
return $this->db->count_all($this->db->dbprefix . 'page');
}
Here you should add the same where clause.
Simple fix thanks to #KyleK suggestion I copied the code from the get_pages_within function and then returned return $query->num_rows();
All working
public function get_total_pages() {
$this->db->select('*');
$this->db->from($this->db->dbprefix . 'page_to_category p2c', 'LEFT');
$this->db->join($this->db->dbprefix . 'page p', 'p.page_id = p2c.page_id', 'LEFT');
$this->db->join($this->db->dbprefix . 'page_description pd', 'pd.page_id = p2c.page_id', 'LEFT');
$this->db->like('p2c.parent_id', (int)$this->uri->segment(4));
$this->db->or_like('p2c.category_id', (int)$this->uri->segment(4));
$query = $this->db->get();
return $query->num_rows();
}

Error Message show encountered Severity: Notice Message:

On my controller for development I have added error_reporting(0); just below the opening php tag on my controller. So will not show some errors.
When go to live mode and remove or comment out the added error_reporting(0); I get a couple of errors
A PHP Error was encountered Severity: Notice Message: Undefined
variable: other_sub Filename: common/Filemanager.php
A PHP Error was encountered Severity: Notice Message: Undefined
variable: histSub Filename: common/Filemanager.php
Question: I have those variables defined not sure why errors showing?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//error_reporting(0);
class Filemanager extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->library('pagination');
$this->lang->load('admin/common/filemanager', 'english');
$this->load->model('admin/tool/model_tool_image');
}
public function index() {
$directory = FCPATH . 'image/catalog/';
$element = $this->input->get('element'); // Element
$input = $this->input->get('input'); // Target
$sub_get = $this->input->get("sub"); // Sub Folders
$end_url = '?';
$end_url .= 'input='.$input;
$end_url .= '&element='.$element;
$endHist = $end_url;
$uris = $this->uri->segment_array();
$sub_folder = "";
if ($sub_get) {
$sub_folder = $sub_get;
}
if ($sub_folder) {
$end_url .= '&sub=' .$sub_folder;
if (sizeof($uris) >3 ) {
for ($i=3; $i < sizeof($uris); $i++) {
$directory .= $uris[$i].'/';
$other_sub .= $uris[$i].'/';
}
$directory .= $sub_folder.'/';
$other_sub .= $sub_folder.'/';
} else {
$directory .= $sub_folder.'/';
$other_sub = $sub_folder.'/';
}
}
$data['images'] = array();
// Get directories
$directories = glob($directory . '*', GLOB_ONLYDIR);
if (!$directories) {
$directories = array();
}
// Get files
$files = 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);
// Get total number of files and directories
$image_total = count($images);
$per_page = 8;
$segment = $this->input->get('per_page');
$segment += $per_page;
foreach ($images as $key => $image) {
if ($key < $segment && $key >= $segment-$per_page) {
$name = str_split(basename($image), 18);
if (is_dir($image)) {
$data['images'][] = array(
'thumb' => '',
'name' => implode(' ', $name),
'type' => 'directory',
'path' => utf8_substr($image, utf8_strlen(FCPATH .'image/')),
'href' => site_url('admin/filemanager') .'/'. utf8_substr($image, utf8_strlen(FCPATH . 'image/catalog/')),
);
} elseif (is_file($image)) {
$subDirect = 'catalog/'.$other_sub;
$data['images'][] = array(
'thumb' => $this->model_tool_image->resize(utf8_substr($image, utf8_strlen(DIR_IMAGE)), 100, 100),
'name' => implode(' ', $name),
'type' => 'image',
'path' => $subDirect.utf8_substr($image, utf8_strlen($directory)),
'href' => base_url() . 'image/' . utf8_substr($image, utf8_strlen(FCPATH . 'image/catalog/'))
);
}
}
}
$data['title'] = "Image Manager";
$data['heading_title'] = "Image Manager";
if (isset($sub_folder)) {
$data['directory'] = $this->uri->segment(3) .'/'. $this->uri->segment(4);
} else {
$data['directory'] = '';
}
if ($element) {
$data['element'] = $element;
} else {
$data['element'] = "";
}
if ($input) {
$data['target'] = $input;
} else {
$data['target'] = "";
}
$endRep = $end_url == '?' ? '' : rtrim($end_url,'&');
// Sets go to previous parent folder.
if ($other_sub) {
$arraySub = explode('/', rtrim($other_sub,'/'));
unset($arraySub[sizeof($arraySub) -1]);
$histSub = "";
foreach ($arraySub as $one) {
$histSub .= $one.'/';
}
$endHist .= "&sub=".$arraySub[sizeof($arraySub) - 1];
}
// Parent folder link
$data['parent'] = site_url('admin/filemanager') .'/'. $histSub . $endHist;
// Refesh current Page
$data['refresh'] = current_url().$endRep;
$config['base_url'] = base_url('admin/filemanager/') .'/'. $other_sub.$endRep;
$config['end_url'] = $end_url == '?' ? '' : rtrim($end_url,'&');
$config['total_rows'] = $image_total;
$config['per_page'] = $per_page;
$config['page_query_string'] = TRUE;
$config['num_links'] = "16";
$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['pagination'] = $this->pagination->create_links();
return $this->load->view('template/common/filemanager_view', $data);
}
}
Problem now solved I had to change a few things and make the input->get setup a lot more simple now works fine.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Filemanager extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->library('pagination');
$this->lang->load('admin/common/filemanager', 'english');
$this->load->model('admin/tool/model_tool_image');
}
public function index() {
$input_get_directory = $this->input->get('directory');
$input_get_page = $this->input->get('page');
$input_get_filter = $this->input->get('filter_name');
$input_get_target = $this->input->get('target');
$input_get_thumb = $this->input->get('thumb');
if (isset($input_get_filter)) {
$filter_name = $input_get_filter .'/';
} else {
$filter_name = null;
}
// Make sure we have the correct directory
if (isset($input_get_directory)) {
$directory = FCPATH . 'image/catalog/' . $input_get_directory;
} else {
// Do not add extra tralier slash at end /
$directory = FCPATH . 'image/catalog';
}
if (isset($input_get_page)) {
$page = $input_get_page;
} else {
$page = 1;
}
$data['images'] = array();
// Get directories
$directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR);
if (!$directories) {
$directories = array();
}
// Get files
$files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE);
if (!$files) {
$files = array();
}
// Merge directories and files
$images = array_merge($directories, $files);
// Get total number of files and directories
$image_total = count($images);
// Split the array based on current page number and max number of items per page of 10
$images = array_splice($images, ($page - 1) * 16, 16);
foreach ($images as $image) {
$name = str_split(basename($image), 14);
if (is_dir($image)) {
$url = '';
if (isset($input_get_target)) {
$url .= '&target=' . $input_get_target;
}
if (isset($input_get_thumb)) {
$url .= '&thumb=' . $input_get_thumb;
}
$data['images'][] = array(
'thumb' => '',
'name' => implode(' ', $name),
'type' => 'directory',
'path' => utf8_substr($image, utf8_strlen(FCPATH . 'image/')),
'href' => site_url('admin/common/filemanager' . '?&token=' . $this->session->userdata('token') . '?&directory=' . utf8_substr($image, utf8_strlen(FCPATH . 'image/' . 'catalog/')) . $url)
);
} elseif (is_file($image)) {
$data['images'][] = array(
'thumb' => $this->model_tool_image->resize(utf8_substr($image, utf8_strlen(FCPATH . 'image/')), 100, 100),
'name' => implode(' ', $name),
'type' => 'image',
'path' => utf8_substr($image, utf8_strlen(FCPATH . 'image/')),
'href' => base_url() . 'image/' . utf8_substr($image, utf8_strlen(FCPATH . 'image/'))
);
}
}
$data['heading_title'] = "Image Manager";
$data['text_no_results'] = "No Results";
$data['text_confirm'] = "Are You Sure";
$data['entry_search'] = "Search..";
$data['entry_folder'] = "New Folder";
$data['button_parent'] = "Parent";
$data['button_refresh'] = "Refresh";
$data['button_upload'] = "Upload";
$data['button_folder'] = "New Folder";
$data['button_delete'] = "Delete";
$data['button_search'] = "Search";
// Session token for ajax
$data['token'] = $this->session->userdata('token');
if (isset($input_get_directory)) {
$data['directory'] = $input_get_directory;
} else {
$data['directory'] = '';
}
// Return the filter name
if (isset($input_get_filter)) {
$data['filter_name'] = $input_get_filter;
} else {
$data['filter_name'] = '';
}
// Return the target ID for the file manager to set the value
if (isset($input_get_target)) {
$data['target'] = $input_get_target;
} else {
$data['target'] = '';
}
// Return the thumbnail for the file manager to show a thumbnail
if (isset($input_get_thumb)) {
$data['thumb'] = $input_get_thumb;
} else {
$data['thumb'] = '';
}
// Parent
$url = '';
if (isset($input_get_directory)) {
$pos = strrpos($input_get_directory, '/');
if ($pos) {
$url .= '?&directory=' . substr($input_get_directory, 0, $pos);
}
}
$data['parent'] = site_url('admin/common/filemanager' .'?&token='. $this->session->userdata('token') . $url);
// Refresh
$url = '';
if (isset($input_get_directory)) {
$url .= '?&directory=' . $input_get_directory;
}
$data['refresh'] = site_url('admin/common/filemanager' .'?&token='. $this->session->userdata('token') . $url);
$this->load->view('template/common/filemanager_view', $data);
}
}

Resources