我在Win 7机器上的XAMPP上开发了我的网站,它在localhost上运行得很好。当我把它上传到实时服务器(linux)时。它开始向我显示这个错误:
Fatal error: Class 'Frontend_Controller' not found in /home/acephm3/public_html/phenomesoft.com/application/controllers/Home.php on line 3
我已经检查并应用了谷歌上的所有内容,但一点运气都没有。
我使用的是CI 3.0.3版本。
我已经设置了$config['subclass_prefix'] = 'MY_';
在/application/core
:中创建如下My_Controller.php
class My_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
// Your own constructor code
}
public function send_mail($from, $from_name, $to, $subject, $message, $smtp, $debug) {
$this->load->library('email');
if (!$smtp) {
$this->email->from($from, $from_name);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
if ( $this->email->send() ) {
$this->session->set_flashdata('message', 'We''ve received your message. Thank you for contacting us.');
redirect('contact_us');
} else {
if ($debug) {
echo $this->email->print_debugger();
}
return false;
}
}
}
}
包括:
include_once('Frontend_Controller.php');
在/application/core/
中创建Frontend_Controller.php
,如下所示:
class Frontend_Controller extends My_Controller {
public $data;
public function __construct()
{
parent::__construct();
// Your own constructor code
$this->data = array();
}
public function _load_template($tpl, $data)
{
$this->load->view('frontend/includes/header', $data);
$this->load->view('frontend/'.$tpl, $data);
$this->load->view('frontend/includes/footer', $data);
}
}
在apllication/controllers/
:下创建控制器Home.php
class Home extends Frontend_Controller {
public function __construct() {
parent::__construct();
// Your own constructor code
}
public function index(){
$this->_load_template('home', $this->data);
}
}
在routes.php.中设置$route['default_controller'] = 'home';
我还能做什么?请再次注意,我在本地主机上没有问题。
将此代码放在APPPATH . 'config.php'
文件的末尾:
spl_autoload_register(function ($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . '.php')) {
include $file;
}
}
});
更改:
include_once('Frontend_Controller.php');
收件人:
include_once( APPPATH.'core/Frontend_Controller.php' );
在主控制器
我更倾向于使用另一种方法,花了一整天的时间来解决这个问题。
- 从
application/core
文件夹中删除了My_Controller.php
和Frontend_Controller.php
- 在
application/controllers
中创建了一个新的控制器Application.php
,并将其从CI_Controller
扩展而来 - 在
application/controllers
中创建了另一个控制器Frontend.php
,并将其从Application
控制器扩展而来(不要忘记在此Frontend.php
控制器的顶部包含Application.php
) - 现在,在我的实际控制器中,
Home.php
在顶部包括Frontend.php
,并从Frontend
控制器扩展了家庭控制器
仅此而已,现在每次创建新的前端控制器时,都会从Frontend
控制器扩展它。
现在,以同样的方式,我可以为我的后端控制器创建另一个控制器,并从中扩展我的所有后端控制器
享受。。!!
您可以尝试的另一种方法是
文件名:MY_Controller.php
<?php
class MY_Controller extends CI_Controller {
// Code Here
}
class Frontend_Controller extends MY_Controller {
// Code here
}
前端控制器类与MY_controller.php 在同一文件中
家庭控制器
文件名:Home.php
<?php
class Home extends Frontend_Controller {
}