简体   繁体   English

Codeigniter 3.1.2 404 错误

[英]Codeigniter 3.1.2 404 error

I'm try to moving some website from CI 2.x to CI 3.1.2, but after I moving my old website to new CI I get 404 error when I'm access that page.我正在尝试将某些网站从 CI 2.x 移至 CI 3.1.2,但是在将旧网站移至新 CI 后,当我访问该页面时出现 404 错误。

this is my CI structure :这是我的 CI 结构:

Applications
- controller
-- back
-- front
--- Home.php

- libraries
-- front.php

- model
-- home_models.php

- views
-- back
-- front
--- elems
---- head.php
---- foot.php
--- pages
---- home.php
--- display
---- pages.php

Controller Home.php控制器主页.php

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

class Home extends CI_Controller {
    var $data;

    public function __construct(){
        parent::__construct();
    }

    public function index(){
    $data = array();
        $this->front->pages('home',$data);
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

Libraries front.php图书馆front.php

<?php
    class Front {

        protected $_ci;

        function __construct(){
            $this->_ci = &get_instance();
        }

        function pages($page, $data=null){
            $data['head'] = $this->_ci->load->view('front/elems/head', $data, TRUE);
            $data['content'] = $this->_ci->load->view('front/pages/'.$page, $data, TRUE);
            $data['foot'] = $this->_ci->load->view('front/elems/foot', $data, TRUE);
            $this->_ci->load->view('front/display/pages', $data);
        }
    }

?>

in my route :在我的路线中:

$route['default_controller'] = 'front/home';

and in my autoload :在我的自动加载中:

$autoload['libraries'] = array('front');

In old CI that's structure is work, but after I'm trying to implement that structure in 3.1.2 I can't access that page.在旧 CI 中,这种结构是可行的,但是在我尝试在 3.1.2 中实现该结构后,我无法访问该页面。 What's wrong with this.这有什么问题。

Read Upgrading from 2.2.x to 3.0.x阅读从 2.2.x 升级到 3.0.x

  1. Update your CodeIgniter files更新您的 CodeIgniter 文件
  2. Update your classes file names更新您的类文件名
  3. Replace config/mimes.php替换config/mimes.php
  4. Remove $autoload['core'] from your config/autoload.php从你的config/autoload.php删除$autoload['core']
  5. Update Database and Routes files.更新数据库和路由文件。
  6. etc ....等等 ....

I found this way我找到了这种方式

Change my system core Router.php into把我的系统核心Router.php改成

protected function _set_default_controller()
    {
        if (empty($this->default_controller))
        {
            show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
        }

        // Is the method being specified?
        if (!sscanf($this->default_controller, '%[^/]/%[^/]/%s', $directory, $class, $method) !== 2)
        {
            $method = 'index';
        }

        if ( ! file_exists(APPPATH.'controllers'. DIRECTORY_SEPARATOR . $directory. DIRECTORY_SEPARATOR .ucfirst($class).'.php'))
        {
            // This will trigger 404 later
            return;
        }

        $this->set_directory($directory);
        $this->set_class($class);
        $this->set_method($method);

        // Assign routed segments, index starting from 1
        $this->uri->rsegments = array(
            1 => $class,
            2 => $method
        );

        log_message('debug', 'No URI present. Default controller set.');
    }

And it works, but if this is safe?它有效,但如果这是安全的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM