Code Igniter Views Remember Previous Variables! Code Igniter Views Remember Previous Variables! codeigniter codeigniter

Code Igniter Views Remember Previous Variables!


That is interessting, I never came to use it like this but you are right it should not do this, maybe this is some caching option. In worst case you must call it like this:

$this->load->view('test_view', '');

Edit:

I have just checked the Code Igniter code from their repository. The reason for this is that they are really caching the variables:

    /*     * Extract and cache variables     *     * You can either set variables using the dedicated $this->load_vars()     * function or via the second parameter of this function. We'll merge     * the two types and cache them so that views that are embedded within     * other views can have access to these variables.     */     if (is_array($_ci_vars))    {        $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);    }    extract($this->_ci_cached_vars)

If I understood it correctly you must do it unfortunately like this:

$this->load->view('test_view', array('what' => ''));


codeigniter does that by default. I was searching why and then I found this

empty($_ci_vars) OR $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);extract($this->_ci_cached_vars);

on the loader class, but you can use

$this->load->clear_vars();

This will clear the buffer and solve the problem.