Welcome Guest, Not a member yet? Register   Sign In
How to expire/delete/nullify the data array going into a view
#1

[eluser]LeePR[/eluser]
I have a view like this:
Code:
// Main view
$data['foo'] = "bar";
$this->load->view('thing1', $data);
$this->load->view('thing2');
$this->load->view('thing3');
In thing1, I can do
Code:
// 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.
Code:
// Thing 2
echo $foo // gives "bar"
Even if I change thing1 to the following
Code:
// Thing 1
echo $foo // gives "bar"
$foo = null;
and change the main view to
Code:
// 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!
Code:
// 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?
#2

[eluser]LeePR[/eluser]
If I var_dump the CI instance, I see this (actual code, not relevant to the above example):
Code:
["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
Code:
$CI = & get_instance();
$CI->_ci_cached_vars = null; // ???
#3

[eluser]LeePR[/eluser]
`$CI->_ci_cached_vars = null` doesn't work. Anyone?
#4

[eluser]John_Betong[/eluser]
Hi LeePR,

Code:
// 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', $data, TRUE);

$main_view     = $this->load->view('full_page', $data, TRUE);
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:
Code:
<div>
     &lt;?= isset($foo) ? $foo : heading('Spot the Looney ==> $foo has not been set', 1) ?&gt;
   </div>
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB