我尝试将某些网站从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
控制器 Home.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
<?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中实现该结构后,我无法访问该页面。这有什么不对。
答案 0 :(得分:0)
阅读Upgrading from 2.2.x to 3.0.x
config/mimes.php
$autoload[‘core’]
config/autoload.php
答案 1 :(得分:0)
我找到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.');
}
它有效,但如果这是安全的吗?