找不到Codeigniter页面-迁移到Live Server

时间:2018-09-03 11:41:43

标签: codeigniter

我正在将基于CI的代码上传到一个实时网站,并且不断出现错误404。

网络结构如下:

web
  -Application
  -Assets
  -Cache
  -..so on
index.php

这是我的Application / Config / Routes.php文件:

$route['default_controller'] = 'H';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

这是我的H控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class H extends CI_Controller {

     function __construct(){
        parent::__construct();
        if(empty($this->session->userdata("userData")['id'])) redirect('/login');

    }

    public function index()
    {
        $data = array();
        if(isset($_GET['guid'])){
            $data['post'] = getListPost($_GET['guid']);
        }else{
            $data['post'] = getStickyPost();
        }
        $this->load->view('partials/header');
        $this->load->view('home',$data);
        $this->load->view('partials/sidebar-home');
        $this->load->view('partials/footer');
    }
    public function materi()
    {
        $this->load->view('partials/header');
        $this->load->view('management/post/lists');
        $this->load->view('partials/footer');
    }
}

这是我的登录控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends CI_Controller {
    public function index($slug="")
    {
        if(isset($_POST['username'])){
            $cek = $this->checkLogin($_POST['username'], $_POST['password']);
            if($cek){
                $newdata = array("userData"=>array(
                    'name'  => $cek[0]['nama'],
                    'id'  => $cek[0]['id'],
                    'nip'  => $cek[0]['nip'],
                    'jabatan'  => $cek[0]['jabatan'],
                    'unit_kerja'  => $cek[0]['unit_kerja'],
                    'foto'  => $cek[0]['foto'],
                    'hak_akses'  => ($cek[0]['hak_akses_knowledge_management']=="")?"pengguna":$cek[0]['hak_akses_knowledge_management'],
                    'unit_kerja_atasan'  => $cek[0]['unit_kerja_atasan'],
                    'email'     => $_POST['username'],
                    'logged_in' => TRUE));

                $this->session->set_userdata($newdata);
                redirect('/');
            }else{
                $this->session->set_flashdata('login_status','false'); 
                redirect('/login');
            }   
        }
        // $this->load->view('partials/header');
        // $this->load->view('partials/login');
        // $this->load->view('partials/footer');
        $this->load->view('partials/single_login');
    }

    public function logout(){
        $this->session->sess_destroy();
        redirect('/');
    }

    public function newlogin(){
        $this->load->view('partials/single_login');
    }

    function checkLogin($email,$password){
        $this->db->where("nip",$email);
        $this->db->where("password",$password);
        $query  = $this->db->get("data_pegawai"); 
        return $query->result_array();

    }

}

当我将路由更改为默认路由时,它可以正常工作,但是当我返回到“ H”时,它将不断出现错误404。

这是views文件夹的结构:

management
    infografis
    post
    ebook
partials
    header.php
    single_login.php
    footer.php
    sidebar-home.php
    login.php
category
    infografis.php
    ebook.php
errors
home.php
post.php
welcome_message.php

1 个答案:

答案 0 :(得分:0)

即使Controller文件名和类名以大写字母开头,路由也应该是小写。

因此,H.phpclass H extends CI_Controller的大小写正确。但是,$route['default_controller']应该分配为小写值。

尝试使用 $route['default_controller'] = 'h';而不是'H',您应该已经启动并运行