Welcome Guest, Not a member yet? Register   Sign In
Extending the controller class: can you spot my error?
#1

[eluser]steward[/eluser]
1. Change the CI prefix:

system/application/config.php

Code:
$config['subclass_prefix'] = 'HANK_'; // 'MY_';


2. Extend the base controller

"Note: If you need to use a constructor in your class make sure you extend the parent constructor"

application/libraries/HANK_controller.php

Code:
class HankController extends Controller {

    public $foo;

    function HankController()
    {
        parent::Controller; // THIS IS THE ERROR LINE 19
    }
}
}

3. "If you are extending the Controller core class, then be sure to extend your new class in your application controller's constructors."

application/controllers/videos.php

Code:
class Videos extends HankController {

    function Videos()
    {
        parent::HankController();
    }

    function index()
    {
        echo $this->foo;
    }

Result:


Fatal error: Undefined class constant 'Controller' in C:\home\...\system\application\libraries\HANK_Controller.php on line 19
#2

[eluser]derekmichaeljohnson[/eluser]
Your class needs to be Hank_Controller not HankController.
Code:
class Hank_Controller extends Controller {

    public $foo;

    function Hank_Controller()
    {
        parent::Controller(); // THIS IS THE ERROR LINE 19
    }
}
}
Also:
Code:
class Videos extends Hank_Controller {

    function Videos()
    {
        parent::Hank_Controller();
    }

    function index()
    {
        echo $this->foo;
    }
#3

[eluser]Frank Berger[/eluser]
[quote author="steward" date="1242596988"]1. Change the CI prefix:
application/libraries/HANK_controller.php
Code:
class HankController extends Controller {

    public $foo;

    function HankController()
    {
        parent::Controller; // THIS IS THE ERROR LINE 19
    }
}
}

Fatal error: Undefined class constant 'Controller' in C:\home\...\system\application\libraries\HANK_Controller.php on line 19
[/quote]

As the error states, you're trying to call a constant, and it is true, you're calling a constant. What you want to do is calling a method, so change this:
Code:
function HankController()
    {
        parent::Controller; // THIS IS THE ERROR LINE 19
    }

to this:

Code:
function HankController()
    {
        parent::Controller(); // THIS IS THE ERROR LINE 19
    }

cheers Frank




Theme © iAndrew 2016 - Forum software by © MyBB