Welcome Guest, Not a member yet? Register   Sign In
MY_Controller in ci2

Is there any relevant documentation for MY_Controller for the current version of CI ?

Hi. I'm learning codeigniter, and I'm experimenting with a project using version 2.02, the latest available version.

I wanted to figure out how to maniupulate multiple view, and pass data to them.
The documentation keeps leading me back to this page:

However, that page starts with the warning:
Quote:Take care - these instructions are for CodeIgniter 1.7.x - the 2.x release sees MY_ class extenders relocated to app/core - see the relevant documentation for 2.x.

I can't seem to find a similar document that has the same documentation, but for 2.x version of CI.

Is there any updated documentation for doing the same thing, but for later version of CI?

// MY_Controller - application/core/MY_Controller.php
class Any_name extends CI_Contoller {

    // Not needed unless setting things
    public function __construct()

Now you extend your other controllers from Any_name


So if I wanted to set $data in the Any_name base controller, how would I do that, and how would I access that data in the controllers that extend Any_name? $this->data? Could you provide a little bit of code for me to illustrate this (for CI 2.x). What I want to do is pass $data to a view, but define $data in the base controller. There's not much out there on this subject. Thanks.

you can do something like that:

class MY_Controller extends CI_Controller
    function __construct()

        $this->your_variable = 'Test Value';


And access it later on in your controllers:

Phil Sturgeon has more informations about setting up base controllers in his blog:

Theme © iAndrew 2016 - Forum software by © MyBB