大家早上好。
我已经在 codeigniter3 hmvc 中建立了一个网站。所有路由和回调函数在我的本地主机 xampp 上都能完美运行,在 godday 共享托管实时服务器上上传项目后,我面临回调函数问题,日志文件中显示以下错误我不明白为什么会发生这种情况。我的用户日志记录功能也显示此错误:-
无法访问与您的字段名称密码对应的错误消息。(验证登录)
codeigniter的logs文件夹中的错误日志
ERROR - 2015-09-16 01:30:08 --> 404 Page Not Found:
ERROR - 2015-09-16 01:30:29 --> 404 Page Not Found: /index
ERROR - 2015-09-16 01:30:30 --> 404 Page Not Found:
ERROR - 2015-09-16 01:31:30 --> Could not find the language line "form_validation_verifylogin"
ERROR - 2015-09-16 01:31:30 --> 404 Page Not Found: /index
这些是我的应用程序/config/config.php
$config['index_page'] = "index.php?";
$config['uri_protocol'] = "QUERY_STRING";
$config['url_suffix'] = '';
$config['language'] = 'english';
Bellow 是我的 application/config/routes.php 设置
$route['Frontend/album_photos/(:num)/(:any)/(:num)'] = 'Frontend/album_photos/index/$1/$2/$3';
$route['Frontend/album_photos/(:num)/(:any)'] = 'Frontend/album_photos/index/$1/$2';
$route['Frontend/news_detail/(:num)/(:any)'] = 'Frontend/news_detail/index/$1/$2';
$route['(:any)/(:any)'] = 'Frontend/index/$1';
$route['(:any)'] = 'Frontend/index/$i';
$route['default_controller'] = 'Frontend/index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['Frontend/download_documents'] = 'Frontend/download_documents/$1';
//these routes works for admin panel
$route['Users/index'] = 'Users/index';
$route['Users/validate_login'] = 'Users/validate_login';
$route['Users/logout'] = 'Users/logout';
$route['Dashboard/index'] ='Dashboard/index';
$route['Aps_pages/manage'] ='Aps_pages/manage';
$route['Aps_pages/create'] ='Aps_pages/create';
$route['Aps_pages/submit'] ='Aps_pages/submit';
$route['Aps_pages/delete'] ='Aps_pages/delete';
$route['Aps_news/manage'] ='Aps_news/manage';
$route['Aps_news/create'] ='Aps_news/create';
$route['Aps_news/submit'] ='Aps_news/submit';
$route['Aps_news/delete'] ='Aps_news/delete';
$route['Aps_events/manage'] ='Aps_events/manage';
$route['Aps_events/create'] ='Aps_events/create';
$route['Aps_events/submit'] ='Aps_events/submit';
$route['Aps_events/delete'] ='Aps_events/delete';
$route['Document_upload/manage'] ='Document_upload/manage';
$route['Document_upload/create'] ='Document_upload/create';
$route['Document_upload/submit'] ='Document_upload/submit';
$route['Document_upload/delete'] ='Document_upload/delete';
$route['Aps_image_slider/manage'] ='Aps_image_slider/manage';
$route['Aps_image_slider/create'] ='Aps_image_slider/create';
$route['Aps_image_slider/submit'] ='Aps_image_slider/submit';
$route['Aps_image_slider/delete'] ='Aps_image_slider/delete';
$route['Aps_testimonials/manage'] ='Aps_testimonials/manage';
$route['Aps_testimonials/create'] ='Aps_testimonials/create';
$route['Aps_testimonials/submit'] ='Aps_testimonials/submit';
$route['Aps_testimonials/delete'] ='Aps_testimonials/delete';
$route['Aps_album_photo/manage'] ='Aps_album_photo/manage';
$route['Aps_album_photo/create'] ='Aps_album_photo/create';
$route['Aps_album_photo/submit'] ='Aps_album_photo/submit';
$route['Aps_album_photo/delete'] ='Aps_album_photo/delete';
$route['Aps_album_photo/search_result'] ='Aps_album_photo/search_result';
$route['Aps_photo_album/manage'] ='Aps_photo_album/manage';
$route['Aps_photo_album/create'] ='Aps_photo_album/create';
$route['Aps_photo_album/submit'] ='Aps_photo_album/submit';
$route['Aps_photo_album/delete'] ='Aps_photo_album/delete';
这是我在前端模块中的 Home.php 控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends MX_Controller
{
public $data =array();
function __construct()
{
parent::__construct();
$this->load->model('mdl_home');
$this->load->helper('site_helper');
$this->load->library('pagination');
}
public function index()
{
$slug = (string)$this->uri->segment(1);
//die($slug.'=is a slug');
$this->data['page'] = $this->mdl_home->get_pages(trim($slug));
// Fetch the page data
if(!empty($this->data['page'])){
$method = '_' .trim($this->data['page']->ViewTemplate);
if (method_exists($this, $method)) {
$this->$method();
}
else {
//die('nothing found method not found');
log_message('error', 'Could not load template ' . $method .' in file ' . __FILE__ . ' at line ' . __LINE__);
show_error('Could not load template ' . $method);
}
//some config to view out put
$this->data['view_file'] = $this->data['page']->ViewTemplate;
$this->data['module_name'] ='Frontend';
//these variable used for main page layout meta keywords description title
$this->data['page_title'] = $this->data['page']->Title;
$this->data['keywords'] = $this->data['page']->Keywords;
$this->data['description'] = $this->data['page']->Description;
$this->data['body'] = $this->data['page']->Body;
//load template module for front end
$this->load->module('Template');
$this->template->frontend_layout($this->data);
}else{
show_404();
}
}
//home page method
private function _home_page(){
$this->data['SliderList'] = $this->mdl_home->get_slider_list();
$this->data['NewsList'] = $this->mdl_home->get_news_with_limit('aps_news',12,'','','NewsDate DESC');
$this->data['EventsList'] = $this->mdl_home->get_event_list();
$this->data['TestimonialList'] = $this->mdl_home->get_testimonial_list();
$this->data['Documents'] = $this->mdl_home->get_uploaded_documents();
}
//this method is for static pages
private function _static_page(){
}
//this method load news page
private function _news_page(){
$table = 'aps_news';
$offset = ($this->uri->segment(2) != '' ? $this->uri->segment(2): 0);
$config['total_rows'] = $this->mdl_home->total_rows($table);
$config['per_page']= 20;
$config['uri_segment'] = 2;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = floor($choice);
$config['base_url']= site_url((string)$this->uri->segment(1));
$this->pagination->initialize($config);
$this->data['paginglinks'] = $this->pagination->create_links();
$this->data['NewsList'] = $this->mdl_home->get_news_with_limit($table,$config["per_page"], $offset,'NewsDate DESC');
}
//this method load contact page
private function _contact_page(){
}
//this method load events page
private function _events_page(){
$table = 'aps_events';
$offset = ($this->uri->segment(2) != '' ? $this->uri->segment(2): 0);
$config['total_rows'] = $this->mdl_home->total_rows($table);
$config['per_page']= 20;
$config['uri_segment'] = 2;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = floor($choice);
$config['base_url']= site_url((string)$this->uri->segment(1));
$this->pagination->initialize($config);
$this->data['paginglinks'] = $this->pagination->create_links();
$this->data['EventsList'] = $this->mdl_home->get_with_limit($table,$config["per_page"], $offset,'EventDate DESC');
}
//this method load photo album page
private function _album_page(){
$table = 'aps_photo_album';
$offset = ($this->uri->segment(2) != '' ? $this->uri->segment(2): 0);
$config['total_rows'] = $this->mdl_home->total_rows($table);
$config['per_page']= 12;
$config['uri_segment'] = 2;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = floor($choice);
$config['base_url']= site_url((string)$this->uri->segment(1));
$this->pagination->initialize($config);
$this->data['paginglinks'] = $this->pagination->create_links();
$this->data['AlbumList'] = $this->mdl_home->get_with_limit($table,$config["per_page"], $offset,'AlbumID DESC');
}
public function download_documents($file){
$this->load->helper('download');
$path = './assets/uploaded_documents/'.$file;
force_download($path, NULL);
redirect(base_url());
}
}
这是我的表单验证库文件
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation{
function run($module = '', $group = ''){
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
这是我的用户控制器文件
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Users extends MX_Controller
{
public function __construct()
{
parent::__construct();
//load financial year
$this->load->model('mdl_users');
}
public function index()
{
if($this->session->userdata('logged_in'))
{
redirect('Dashboard');
}else
{
$this->login();
}
}
//this function used to show login form view in template one column layout view
public function login()
{
$data['view_file'] = "loginform";
$data['module_name'] ='Users';
$data['page_title'] = 'Login Page';
$this->load->module('Template');
$this->template->login_layout($data);
}
//after entering the login values login form submit value handled by this function or method
public function validate_login()
{
$this->form_validation->set_error_delimiters('<div style="color:red;">', '</div>');
$this->form_validation->set_rules('username', 'Username', 'required|max_length[30]|xss_clean');
$this->form_validation->set_rules('password','Password', 'required|callback_verify_login');
if ($this->form_validation->run($this) == FALSE)
{
$this->index();
}
}
//this function for callback validation after submit button press
public function verify_login() {
$username = $this->input->post('username');
$password = $this->input->post('password');
//this method is in model folder/directory which interact with database https://www.youtube.com/watch?v=8fy8E_C5_qQ
$user = $this->mdl_users->check_login_authentication($username, $password);
if(empty($user)){
$this->form_validation->set_message('verify_login', 'Sorry the details you provided have not been found');
return FALSE;
}else{
//set user data in session and redirect to dashboard
$data = array(
'username' =>$user->UserName,
'userid' => $user->UserID,
'logged_in' => TRUE
);
$this->session->set_userdata($data);
redirect('Dashboard');
}
}
//logout function
public function logout()
{
$this->session->sess_destroy();
redirect('Users');
}
}