Welcome Guest, Not a member yet? Register   Sign In
Variable scope
#1

[eluser]The Mask[/eluser]
Hi,
I'd like to define variables in a controller that ALL other controllers extend so that they are available in any controller and any function.

i.e.

class My_Controller extends Controller
{
var $data = 123;

etc...
}

class Home extends My_Controller
{

function index()
{
$this->load->view( 'home_view', $data );
}

}

I have a scoping issue with $data, what is the best way to achieve this?
I know I can introduce 'global' scope for $data but is there anything in CI I can use?

Thanks
#2

[eluser]ontguy[/eluser]
Change this:
Code:
$this->load->view( ‘home_view’, $data );


to this:
Code:
$this->load->view( ‘home_view’, $this->data );


That should achieve what you have in mind.
#3

[eluser]The Mask[/eluser]
Yep, of course.
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB