在我的控制器上,我试图能够显示一条消息,其中包含1 “你的第1页”等
如果从1开始它从0开始“你的在页面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;
问题:我如何确保它可以在消息中从1而不是0计数而不影响控制器上的主分页
控制器
<?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);
}
}
答案 0 :(得分:0)
它最终是一个简单的修复,因为脑屁应该立即将它捡起来。
我改变了
(($start - 1) * $config['per_page']) + 1 : 0)
要
(($start - 0) * $config['per_page']) + 1 : 0)