扩展核心类代码点火器-404错误


Extending Core Class Codeigniter - 404 Error

我正在努力学习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($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);
  }
}

现在我开始把家庭控制器写为:

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页找不到错误。如何更改我的应用程序以使用my_Controller?

我在扩展核心类时也遇到了这个问题。我的问题是,它在我的本地服务器上工作,但在我的生产服务器上不工作。我在生产中收到了404错误,而且只在我的控制器上使用了类扩展。经过一些研究,我注意到我的本地服务器运行的是php 5.3.x版本,而我的生产服务器运行的却是5.2.x版本。为了解决这个问题,我不得不将生产服务器升级到5.3版本。

要了解您的网站使用的php版本,请将以下命令放在您的视图中:

<?php echo phpversion() ?>