Search code examples
phpoopcodeigniterextend

Extending CI_Controller


All I'm trying to do is something fairly simple :

  • Create a class (let's say brandNewClass - NOT MY_Controller) which extends CI_Controller
  • Create other controllers which extend brandNewClass

E.g.

class brandNewClass extends CI_Controller {

    public function index()
    {

    }

    public function info()
    {

    }
}

used like (in a file under /controllers) :

<?php

class newController extends brandNewClass
{
}

?>

The thing is, although it works when I'm copying the file under /application/core and naming it as MY_Controller, when I change the name to something more... self-explanatory, it doesn't.

Fatal error: Class 'brandNewClass' not found in .... on line ..

I've even tried using the __autoload function mentioned here, but without any luck.

Any ideas?


Solution

  • Have a look at this excellent tutorial - I hope it helps

    http://codeigniter.tv/a-10/Extending-the-core-MY_Controller-and-beyond