EllisLab text mark
Advanced Search
     
How to expire/delete/nullify the data array going into a view
Posted: 07 September 2007 06:53 PM   [ Ignore ]
Joined: 2007-06-04
16 posts

I have a view like this:

// Main view
$data['foo'"bar";
$this->load->view('thing1'$data);
$this->load->view('thing2');
$this->load->view('thing3'); 
In thing1, I can do
// Thing 1
echo $foo // gives "bar" 
however, even though I’m no passing the data array into thing2, thing2 will still see the data e.g.
// Thing 2
echo $foo // gives "bar" 
Even if I change thing1 to the following
// Thing 1
echo $foo // gives "bar"
$foo null
and change the main view to
// Main view
$data['foo'"bar";
$this->load->view('thing1'$data);
$data null;
$this->load->view('thing2'null);
$this->load->view('thing3');
thing2 is still printing out bar!
// Thing 2
echo $foo // gives "bar" 

Caching is off AFAIK (I haven’t explicitly turned it on anywhere). Can anyone tell me how I might reset the data array?

 
Posted: 07 September 2007 06:58 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2007-06-04
16 posts

If I var_dump the CI instance, I see this (actual code, not relevant to the above example):

["load"]=>
  &
object;(CI_Loader)#10 (26) {
    
["_ci_ob_level"]=>
    
int(0)
    
["_ci_view_path"]=>
    
string(70"/home/lee/Development/rsfs/CodeIgniter_1.5.4/system/application/views/"
    
["_ci_is_php5"]=>
    
bool(true)
    
["_ci_is_instance"]=>
    
bool(false)
    
["_ci_cached_vars"]=>
    array(
8{
      [
"view"]=>
      
string(14"create_account"
      
["vars"]=>
      array(
0{
      }
      [
"return"]=>
      
bool(false)
      
["labelFor"]=>
      
string(6"fm-req"
      
["labelDesc"]=>
      
string(13"State Issued:"
      
["selectId"]=>
      
string(11"stateIssued"
      
["selectName"]=>
      
string(11"stateIssued"
      
["divClass"]=>
      
string(6"fm-req"
    

The “state issued” stuff is the stuff I’m trying to get rid of. Is it safe to just do something like

$CI = & get_instance();
$CI->_ci_cached_vars null// ??? 
 
Posted: 07 September 2007 07:21 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-06-04
16 posts

`$CI->_ci_cached_vars = null` doesn’t work. Anyone?

 
Posted: 07 September 2007 10:35 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2006-12-26
727 posts

Hi LeePR,

// Main view
 
$data['top']   $this->load->view('thing2'''TRUE);
 
$data['body']  $this->load->view('thing3'''TRUE);

 
$data['foo']   "bar"// NOT IN ABOVE SCOPE BUT VISIBLE
 
$data['foot']  $this->load->view('thing1'$dataTRUE);
 
 
$main_view     $this->load->view('full_page'$dataTRUE);
 echo  
$main_view

 
Try the above, it should work.
 

I believe the method $this->load->view(...) sole purpose is to output a single view/html webpage.
 
Ironically my problem is usually “Variable not declared” so I tend to use code such as the following:

<div>
     
<?= isset($foo) ? $foo heading('Spot the Looney ==> $foo has not been set'1?>
   
</div

 

 Signature 

Joke of the day - Bulletin Board Ideas     (ongoing development site)

My Hippy Trail    Source code   

Latest Project