Reputation: 5121
I have developed my website at XAMPP on Win 7 machine, and it works perfect on localhost. When I uploaded it to a live server (linux). It started showing me this error:
Fatal error: Class 'Frontend_Controller' not found in /home/acephm3/public_html/phenomesoft.com/application/controllers/Home.php on line 3
I've checked and applied everything I could from google but no luck at all.
I am using CI version 3.0.3.
I have set $config['subclass_prefix'] = 'MY_';
Created My_Controller.php
as follows in /application/core
:
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;
}
}
}
}
Included:
include_once('Frontend_Controller.php');
Created Frontend_Controller.php
in /application/core/
as follows:
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);
}
}
Created a controller Home.php
under apllication/controllers/
:
class Home extends Frontend_Controller {
public function __construct() {
parent::__construct();
// Your own constructor code
}
public function index(){
$this->_load_template('home', $this->data);
}
}
Set $route['default_controller'] = 'home';
in routes.php.
What else I have to do? Please note it once again that I have no issues on localhost.
Upvotes: 1
Views: 2354
Reputation:
Another way you could try is
Filename: MY_Controller.php
<?php
class MY_Controller extends CI_Controller {
// Code Here
}
class Frontend_Controller extends MY_Controller {
// Code here
}
With the front end controller class on the same file as MY_Controller.php
Home Controller
File name: Home.php
<?php
class Home extends Frontend_Controller {
}
Upvotes: 0
Reputation: 5121
I rather used another approach, took me a whole day to figure this out.
My_Controller.php
and Frontend_Controller.php
from application/core
folder.Application.php
in application/controllers
and extended it from CI_Controller
.Frontend.php
in application/controllers
and extended it from Application
controller (Don't forget to include Application.php
at top of this Frontend.php
controller).Home.php
included Frontend.php
at the top and extended home controller from Frontend
controller.That's all, now every time you create a new frontend controller extend it from Frontend
controller.
Now in the same way I can create another controller for my backend controllers and extend all my backend controllers from it.
Enjoy..!!
Upvotes: 1
Reputation: 138
Change:
include_once('Frontend_Controller.php');
To:
include_once( APPPATH.'core/Frontend_Controller.php' );
In Home controller
Upvotes: 2
Reputation: 7111
Put this code at the end of APPPATH . 'config.php'
file:
spl_autoload_register(function ($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . '.php')) {
include $file;
}
}
});
Upvotes: 3