【问题标题】:Codeigniter 3.1.2 404 errorCodeigniter 3.1.2 404 错误
【发布时间】:2017-01-19 17:50:45
【问题描述】:

我正在尝试将一些网站从 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 中实现该结构之后,我无法访问该页面。这有什么问题。

【问题讨论】:

标签: php codeigniter codeigniter-3


【解决方案1】:

阅读Upgrading from 2.2.x to 3.0.x

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

【讨论】:

    【解决方案2】:

    我找到this方式

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

    它有效,但如果这样安全吗?

    【讨论】:

    猜你喜欢
    • 2014-12-23
    • 2014-03-25
    • 2013-05-23
    • 2013-01-29
    • 2014-05-25
    • 2014-10-14
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多