I’m not really sure whether this is a ‘bug’, but from a usability standpoint I think it would make sense for things to function as I’m about to describe.
Currently the variables that are extracted for use within views will persist across multiple calls to the load->view() function, if you use many views, and each view has similar page elements on it, it’s difficult to keep all of the variable names straight and make sure you don’t reuse them. For example:
Index function within Controller:
function index()
{
$data['print'] = true;
$data['content'] = "content";
$this->load->view('debug',$data);
$other_data['content'] = "other content";
$this->load->view('debug',$other_data);
}
Debug View file:
<p><?php
if(isset($print))
print_r($content);
?></p>
Browser output:
content
other content
Expected output:
content
I know this seems trivial from the example, but in my case I have a ‘Pagebuilder’ library which loads in many views (header, navigation, content, footer) however one of the views and its associated data is specified outside of the library, as seen in the following example:
function index()
{
$this->load->model('blog');
$entries = $this->blog->get_entry_items(10);
$data['content'] = $entries;
//this function loads many other views besides the 'blog' view specified
$this->pagebuilder->build('blog',$data);
}
I ran into a problem earlier where I had collisions with the names of the variables passed to the views. It’s a problem that’s easily solved by keeping track of all the variable names used within the views, but things working like this breaks the encapsulation of my Pagebuilder class. Ideally each of the variables passed to a view would be unset (or through some other method made inaccessible to other views) after that view is finished loading.
Anyone think this qualifies as a bug?
