• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MY_Controller in ci2

#1
[eluser]bobdobbs[/eluser]
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:
http://codeigniter.com/wiki/MY_Controller

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?

#2
[eluser]InsiteFX[/eluser]
Code:
// MY_Controller - application/core/MY_Controller.php
class Any_name extends CI_Contoller {

    // Not needed unless setting things
    public function __construct()
    {
        parent::__construct();
    }

}
Now you extend your other controllers from Any_name

InsiteFX

#3
[eluser]sehummel[/eluser]
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.

#4
[eluser]LuckyFella73[/eluser]
you can do something like that:

Code:
<?php
class MY_Controller extends CI_Controller
{
    function __construct()
    {
        parent::__construct();

        $this->your_variable = 'Test Value';

    }
}

And access it later on in your controllers:
Code:
$this->your_variable



EDIT:
Phil Sturgeon has more informations about setting up base controllers in his blog:
http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.