I’m using the latest stable version of Codeigniter.
Here’s part of the controller:
$data = array(
'tracks' => $this->tracks_model->get(NULL, 'start_date'),
'longest_distance' => $this->tracks_model->get(10, 'distance'),
'longest_time' => $this->tracks_model->get(10, 'moving_time')
);
$this->load->view('statistics_view', $data);
and here’s part of the code inside the file statistics_view.php:
<section>
<h3>Section 1</h3>
<?php $this->load->view('podium_view', array('tracks' => $longest_time, 'unit' => 'ore', 'function' => 'minutes_to_hours')) ?>
</section>
<section>
<h3>Section 2</h3>
<?php $this->load->view('podium_view', array('tracks' => $longest_distance, 'unit' => 'km')) ?>
</section>
I’ve noticed that in the 2nd loaded view (inside section 2), the variable $function is still set from section 1, and the other values (traks, unit) are the one I passed.
Why the variable function is still set in the second view?
Shouldn’t be reset?
Codeigniter uses extract in order to convert the array of variables you are passing
see http://php.net/manual/en/function.extract.php
Extract keep adding variable to the symbol table and the view is just included as a PHP file.
So the variable scope is the same and you will have access to all the variables defined early. Default behaviour of extract is it overrides if a conflict is found.
If you want to reset, you will have to pass some value.