Error in extending CodeIgniter Controller [closed]
I am trying to extend the CodeIgniter controller. I have created MY_Controller.php
file, the content of the file is as following:
<?php
class MY_Controller extends CI_Controller
{
function generate_key()
{
$n = rand(10e16, 10e20);
return base_convert($n, 10, 36);
}
Now I create my controllers by extending MY_Controller
instead of CI_Controller
. Following is an example of a controller:
class Member extends MY_Controller
{
public function index()
{
$this->load->view('welcome');
}
I have placed the MY_Controller.php
file in the Application/libraries/
folder. But when I load the application, I get the error:
Fatal error: Class 'MY_Controller' not found in path\to\application\controllers\member.php
Can someone tell me what i am doing wrong? Thanks.
Edit: I'm using CodeIgniter 2.0.2
I had been this issue:
`Fatal error: Class 'MY_Controller' not found ...`
publishing to my remote Linux server (DreamHost) but not on locally on Windows. The issue was Linux being case sensitive: I had MY_Controller.php with a lowecase c and it wasn't autoloading.
Just in case anyone else has the same issue :)
You need to create MY_Controller.php
in application/core
. I tried what you have setup and got the same problem. Moving the custom controller to core
solved the problem.
Hope it helps!
I had problem like this,After some search I found error was made myself,Because my controller class name was MY_Controller but file name was My_Controller[Case not matching]. Note:- In localhost I didnt have any error.
In extended controller I Use
class Home extends MY_Controller{
function __construct() {
parent::__construct();
}
}
even I got the error.
After changing my file name to MY_Controller it started to work well.
MY_contrller places in application/core folder.
精彩评论