Welcome Guest, Not a member yet? Register   Sign In
variables in views
#1

[eluser]Zion.b.y[/eluser]
if you call
$this->view('blocks/someblock', array('x' => 123));
the $x will be available with the value of 123

if after that you will call
$this->view('blocks/someblock');
then the variable $x will still be defined with the value of 123 because the extract function created it in the first call

the solution is this
In class CI_Loader, line 835 , between
include($_ci_path); // include() vs include_once() allows for multiple views with the same name
and
log_message('debug', 'File loaded: '.$_ci_path);

you should place this:

foreach ($_ci_data['_ci_vars'] as $key => $value){
unset($this->_ci_cached_vars[$key]);
unset($$key);
}

this will unset all the block params and they will not be available in the next call to the block

Can someone please show this to codeigniter team so they can fix it in the next version

Thanks.

P.S.
if you have this problem you can extend the class in
application/core/My_Loader.php

and this is the code you should place there:
<?php
Class My_Loader extends CI_Loader{

protected function _ci_load($_ci_data)
{
$result = parent::_ci_load($_ci_data);
foreach ($_ci_data['_ci_vars'] as $key => $value){
unset($this->_ci_cached_vars[$key]);
unset($$key);
}
return $result;
}
}



Messages In This Thread
variables in views - by El Forum - 09-04-2014, 05:01 AM
variables in views - by El Forum - 09-04-2014, 05:31 AM
variables in views - by El Forum - 09-04-2014, 08:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB