扩展核心类Codeigniter - 404错误 [英] Extending Core Class Codeigniter - 404 Error
问题描述
我想学习Codeigniter。我试图在我的CI应用程序中使用application / core / MY_Controller。
MY_Controller.php as:
I am trying to learn Codeigniter. I am trying to use application/core/MY_Controller in my CI application. MY_Controller.php as:
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);
}
}
现在我开始写家庭控制器as:
Now I started to write home controller as :
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.
这里是我的配置和路由文件。
Here are my config and route files.
$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?
I get 404 page not found error . How can I change my application to work with MY_Controller ?
推荐答案
我的问题是,是在我的本地服务器上,但不是在我的生产服务器上。我在生产中收到404错误,并且只在我的控制器上使用类扩展。经过一些研究,我注意到我的本地服务器运行php版本5.3.x,而我的生产服务器运行5.2.x.要解决这个问题,我必须将我的生产服务器升级到5.3。
I also had this problem with extending core classes. My problem was that is was working on my local server, but not on my production server. I was receiving the 404 error in production, and only on my controllers that used the class extensions. After some research I noticed that my local server was running php version 5.3.x, while my production server was running 5.2.x. To fix this I had to upgrade my production server to 5.3.
要查看您的网站使用的是什么版本的php,请将此命令放在您的视图中:
To find out what version of php your site is using, place this command in your view:
<?php echo phpversion() ?>
这篇关于扩展核心类Codeigniter - 404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!