Hi there,
I'm very new to CI but have a background in programming.
I am trying to get my head round variables.
I've created my own controller (MY_Controller) which extends the CI_Controller, and has its own PROTECTED $data = array(), as suggested by many
I set some variables inside that array in the constructor of the MY_Controller class.
$this->data['counter']=1;
Then I've created another Controller which extends MY_Controller and I have a bunch of functions which basically call views which then call back into functions which change the value of that counter.
Problem is, the value doesn't change. For example, this function is supposed to increment the counter value and then call a view to show the counter
public function change_counter()
{
$a = $this->data['counter'];
$a = $a +1;
$this->data['counter'] = $a;
$this->load->view("show_counter",$this->data)
}
But it doesn't increment.
It seems that I can't actually change the value of the variables set in MY_Controller.
How does one change variables? Is the only way to do this sort of thing through Sessions? In which case what is the point of having the global data array in MY_Controller??
Yours,
Confused of Scotland.
I'm very new to CI but have a background in programming.
I am trying to get my head round variables.
I've created my own controller (MY_Controller) which extends the CI_Controller, and has its own PROTECTED $data = array(), as suggested by many
I set some variables inside that array in the constructor of the MY_Controller class.
$this->data['counter']=1;
Then I've created another Controller which extends MY_Controller and I have a bunch of functions which basically call views which then call back into functions which change the value of that counter.
Problem is, the value doesn't change. For example, this function is supposed to increment the counter value and then call a view to show the counter
public function change_counter()
{
$a = $this->data['counter'];
$a = $a +1;
$this->data['counter'] = $a;
$this->load->view("show_counter",$this->data)
}
But it doesn't increment.
It seems that I can't actually change the value of the variables set in MY_Controller.
How does one change variables? Is the only way to do this sort of thing through Sessions? In which case what is the point of having the global data array in MY_Controller??
Yours,
Confused of Scotland.