我已經檢查了這裏關於在CodeIgniter中分頁的幾個線程,但我還沒有找到解決我的問題的方法。CodeIgniter尋呼404
我必須位於控制器,控制器類/管理/ index.php文件稱爲「索引」,它包含以下代碼:
class Index extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper("url");
$this->load->helper('events_helper');
$this->load->helper('delegates_helper');
$this->load->model('admin/event_model');
$this->load->model('admin/delegate_model');
$this->load->library('pagination');
}
public function index() {
$config = array();
$config['base_url'] = base_url() . 'admin';
$config['total_rows'] = $this->event_model->record_count();
$config['per_page'] = 2;
$config['uri_segment'] = 2;
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data['paged_events'] = $this->event_model->get_paged_events($config['per_page'], $page);
$data['links'] = $this->pagination->create_links();
$data['events'] = $this->event_model->get_events();
$data['event_courses'] = $this->event_model->get_event_courses();
$data['event_suppliers'] = $this->event_model->get_event_suppliers();
$data['event_venues'] = $this->event_model->get_event_venues();
$data['event_locations'] = $this->event_model->get_event_locations();
$data['event_statuses'] = $this->event_model->get_event_statuses();
$data['event_prices'] = $this->event_model->get_event_prices();
$data['event_types'] = $this->event_model->get_event_types();
$data['event_tutors'] = $this->event_model->get_event_tutors();
$data['event_delegates'] = $this->event_model->get_event_delegates();
$data['event_delegate_statuses'] = $this->event_model->get_event_delegate_statuses();
$this->load->view('templates/admin/header', $data);
$this->load->view('admin/index', $data);
$this->load->view('templates/admin/footer');
}
}
現在,如果我去到localhost /霜/的public_html /管理員正確的金額的結果顯示以及到下一頁的鏈接呈現,但是當我點擊下一頁或轉到第2頁或第3頁時,出現404錯誤。
現在我試圖改變我的基本URL:
$config['base_url'] = base_url() . 'admin/index';
和:
$config['base_url'] = base_url() . 'admin/index/';
和:
$config['base_url'] = base_url() . 'admin/';
同時也改變了我的uri_segment 1,2和3,但我得到了相同的結果。
我一直在使用,甚至嘗試過:
$route['admin/(:num)'] = 'admin/$1';
和:
$route['admin/(:num)'] = 'admin';
不過,我得到的404錯誤。
這些都是我的「Event_Model」類我的模型功能:
public function record_count() {
$this->db->select_sum('event_active');
$this->db->from('events');
$this->db->where('event_active', 1);
$query = $this->db->get();
$total_active_events = $query->row()->event_active;
if($total_active_events > 0) {
return $total_active_events;
}
return false;
}
public function get_paged_events($limit, $start) {
$this->db->limit($limit, $start);
$this->db->where('events.event_active = 1');
$this->db->order_by('events.event_start_date', 'asc');
$query = $this->db->get('events');
if($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
我有點停留在這一個,並感謝您的幫助。謝謝。
編輯:添加routes.php文件
$route['default_controller'] = "index";
$route['404_override'] = '';
$route['admin/(:num)'] = 'admin/index/$1';
我們可以知道404的URL是什麼嗎? 'localhost/cream/public_html/admin/index/2'我猜? – 2013-03-05 15:37:08
它是http:// localhost/cream/public_html/admin/2,或者如果我將'base_url'更改爲admin/index,它將變爲http:// localhost/cream/public_html/admin/index/2 – 2013-03-05 16:17:33
有沒有人關於這一點的想法,我現在很難過? – 2013-03-06 11:27:54