繁体   English   中英

Codeigniter 3.1.2 404 错误

[英]Codeigniter 3.1.2 404 error

我正在尝试将某些网站从 CI 2.x 移至 CI 3.1.2,但是在将旧网站移至新 CI 后,当我访问该页面时出现 404 错误。

这是我的 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

控制器主页.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 */

图书馆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);
        }
    }

?>

在我的路线中:

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

在我的自动加载中:

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

在旧 CI 中,这种结构是可行的,但是在我尝试在 3.1.2 中实现该结构后,我无法访问该页面。 这有什么问题。

阅读从 2.2.x 升级到 3.0.x

  1. 更新您的 CodeIgniter 文件
  2. 更新您的类文件名
  3. 替换config/mimes.php
  4. 从你的config/autoload.php删除$autoload['core']
  5. 更新数据库和路由文件。
  6. 等等 ....

我找到了这种方式

把我的系统核心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.');
    }

它有效,但如果这是安全的?

暂无
暂无

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

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