Welcome Guest, Not a member yet? Register   Sign In
Extending the controller - problem I can't figure out
#1

[eluser]Daniel H[/eluser]
This is driving me nutes!

MY_Controller.php in app/libraries: (file is spelled correctly and is case sensitive)

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');


class MY_Controller extends Controller
{    
    function MY_Controller()
    {
        parent::Controller();
        
              
        }
    }

}
?>

Then in my Controller...

Code:
<?php

class Projects extends MY_Controller {

    function __construct()
    {
        parent::MY_Controller();
        
    }

Then running projects controller returns

Code:
Fatal error: Class 'MY_Controller' not found in /........../application/controllers/projects.php on line 3

What the heck am I doing wrong?!
#2

[eluser]WanWizard[/eluser]
subclass_prefix set to 'MY_' in the config?

And you have a syntax error in your MY_Controller, unbalanced } ...
#3

[eluser]Daniel H[/eluser]
Yes the subclass MY_ is set. That's not a syntax error - I only included the header of that controller file.
#4

[eluser]ELRafael[/eluser]
CI version?

CI 1.7.X
./system/application/libraries/MY_Controller.php
or
./application/libraries/MY_Controller.php
Code:
class MY_Controller extends Controller {
    function MY_Controller()
    {
        parent::Controller();
    }
}

CI 2.X
./application/core/MY_Controller.php
Code:
class MY_Controller extends Controller {
    function MY_Controller()
    {
        parent::Controller();
    }
}
Only for Controller. If you're planning to extend models, you'll need to use something like that:
Code:
class MY_Model extends CI_Model { //the rest is the same thing

BTW, you are mixing PHP4 and PHP5. If you'll use PHP5, why don't you write all with PHP5 syntax?
public function __construct() for son and father class




Theme © iAndrew 2016 - Forum software by © MyBB