不访问控制器功能,并在CI 3中找到404页面未找到错误

时间:2017-05-22 09:36:52

标签: php .htaccess codeigniter codeigniter-3

我安装了CI 3并添加了我已经重命名的以前版本的Controller和Model文件。我已经浏览了文件,文件名首字母是大写的。 在localhost ie- http://localhost:81/sitename/上运行该站点时,它将显示主页。 但是当控制器名称及其功能名称伴随着网址ie- http://localhost:81/sitename/login时,结果

  

未找到404页面   找不到您请求的页面。

的.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

的config.php

    $config['base_url'] = 'http://localhost:81/sitename/';

    $config['index_page'] = '';
   $config['uri_protocol']  = 'REQUEST_URI'; //tried with AUTO also

routes.php文件

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

autoload.php 我已经提到了url helper

$autoload['helper'] = array('url', 'file');

Controller Member.php

<?php 
class Member extends CI_Controller {

    private $controller = '';
    private $data = array();
    private $base_layout = '';

    function __construct() {
        parent::__construct();
        // $this->load->library('input');
        $this->load->library('email');
        $this->load->model('member_model');
        $this->controller = strtolower(__CLASS__);
        $this->base_layout = 'layouts/main_content';
        $this->is_logged();
    }

    function is_logged() {
        if(!$this->session->userdata('logged_in'))      

            $this->base_layout = 'layouts/login';
            $this->load->view('layouts/login');
    }
 }

Controller Login.php

<?php 

class Login extends CI_Controller {

    private $controller = '';

    function __construct() {
        parent::__construct();
        $this->controller = strtolower(__CLASS__);
        $this->load->model('login_model');

        $this->is_logged();
    }

   public function index() {
        $this->load->view('layouts/login');
    } 

    function is_logged() {
        date_default_timezone_set('Asia/Singapore');
        $sess_data = $this->session->userdata('logged_in');

        if($sess_data) {
            if($sess_data['user_type']=="pre"){
            $c_time = mktime();
            //$c_time = date('h:i:s a');
            $open = strtotime('Today 10am');
            $close = strtotime('Today 8pm');

            if ($c_time > $open && $c_time < $close) {
                redirect('member', 'refresh');
            } else {
                $this->session->unset_userdata('logged_in');
                redirect('login', 'refresh');
            }
            }else{
            redirect('member', 'refresh');}
        }

    }


    function auth() {
        date_default_timezone_set('Asia/Kolkata');
        $this->load->library('form_validation');

        $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');

        if($this->form_validation->run() == FALSE) {
            //Field validation failed.  User redirected to login page           
            redirect('login', 'refresh');
        } elseif($this->input->post('usertype')!="admin") {

            $c_time = mktime();
            //$c_time = date('h:i:s a');
            $open = strtotime('Today 10am');
            $close = strtotime('Today 8pm');

            if ($c_time > $open && $c_time < $close) {
                redirect('member', 'refresh');
            } else {
                redirect('login', 'refresh');
            }
            //redirect('member', 'refresh');

        }

    }
}

当我尝试使用以下链接显示主页但显示的样式不会出现

http://localhost:81/sitename/index.php/login

登录页面是我的主页,但在尝试登录时,请不要输入控制器功能。有关此问题的解决方案吗?

3 个答案:

答案 0 :(得分:2)

将.htaccess更改为:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

答案 1 :(得分:1)

尝试使用以下网址运行

http://localhost:81/sitename/index.php/login

答案 2 :(得分:1)

我刚刚通过添加RewriteBase并设置短打开标记来更改我的.htaccess,这通过正确运行URL帮助我。

RewriteEngine On
RewriteBase /sitename
php_flag short_open_tag on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]