Php 扩展核心类Codeigniter-404错误
我正在努力学习Codeigniter。我正在尝试在我的CI应用程序中使用application/core/MY_Controller。 MY_Controller.php作为:Php 扩展核心类Codeigniter-404错误,php,codeigniter,extending-classes,Php,Codeigniter,Extending Classes,我正在努力学习Codeigniter。我正在尝试在我的CI应用程序中使用application/core/MY_Controller。 MY_Controller.php作为: class MY_Controller extends CI_Controller { protected $data = array(); function __construct() { parent::__construct(); } function render_page($vie
class MY_Controller extends CI_Controller {
protected $data = array();
function __construct() {
parent::__construct();
}
function render_page($view) {
//do this to don't repeat in all controllers...
$this->load->view('templates/header', $this->data);
//menu_data must contain the structure of the menu...
//you can populate it from database or helper
$this->load->view($view, $this->data);
$this->load->view('templates/footer', $this->data);
}
}
现在我开始将home controller编写为:
class Home extends MY_Controller {
function __construct() {
parent::__construct();
}
public function view($page = 'home')
{
$this->load->helper('text');
$data['records']= $this->services_model->getAll();
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('pages/'.$page, $data);
}
我的视图文件夹为
+pages
+home.php
+templates
+footer.php
+header.php.
这是我的配置和路由文件
$config['base_url'] = 'http://localhost/~ytsejam/kirmiziblog/';
$config['index_page'] = 'index.php';
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
我得到404页找不到错误。如何更改我的应用程序以与我的\u控制器一起工作?我在扩展核心类时也遇到了这个问题。我的问题是在本地服务器上工作,而不是在生产服务器上。我在生产中收到404错误,并且仅在使用类扩展的控制器上收到。经过一些研究,我注意到我的本地服务器运行的是php版本5.3.x,而我的生产服务器运行的是5.2.x。为了解决这个问题,我必须将我的生产服务器升级到5.3 要了解站点使用的php版本,请在视图中放置以下命令:
<?php echo phpversion() ?>
您需要调用主页
控制器,而不是页面
$this->load->view('home/'.$page,$data);。。。像这样?像这样:$route['default\u controller']='home/view'$路线['(:any)]='home/view/$1'代码>application/core/MY_Controller.php,另一个文件是application/controllers/home.php。修复了名称错误。我按照你说的路线走了。但仍然是404错误。如果(!file_存在(!application/views/pages/'.$page..php'))将更改为如果(!file_存在(!file_存在(!APPPATH./views/pages/'.$page..php'))
,会发生什么?