Welcome Guest, Not a member yet? Register   Sign In
View Data Issue
#1

(This post was last modified: 10-12-2016, 02:01 PM by mertdogan.)

I found a bug for loading view with second array parameter. I use version 3.1.0.

My controller function:

public function test(){
$data=array('a'=>'A','b'=>'B');
$this->load->view('test',$data);
$data=array();
$data=array('b'=>'B');
$this->load->view('test',$data);
}


and this is my TEST view file:

<?php echo $a.'-'.$b.'|';


If you run this structure; it will generate :

A-B|A-B|

but it must generate and give us a notice message that $a not defined:

A-B|-B|

because we don't define $a for second call of view file.

I tried unset($data) but issues still continues.

I don't know why this happens but it can be a buffer problem or somethink else like this.
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#2

By design the loader caches data passed via $this->load->view('test',$data); So, $a IS defined and remains so between calls to load->view.

Try this variation on you test function

Code:
public function test()
{
$data = array('a' => 'A', 'b' => 'B1');
$this->load->view('test', $data);
$data = array();
$data = array('b' => 'B2');
$this->load->view('test', $data);
}

This will output  A-B1|A-B2|

Again, this is by design.  Look at the source code. Came as a surprise to me too when I first discovered it.
Reply
#3

(10-12-2016, 02:16 PM)dave friend Wrote: By design the loader caches data passed via $this->load->view('test',$data); So, $a IS defined and remains so between calls to load->view.

Try this variation on you test function

Code:
public function test()
{
$data = array('a' => 'A', 'b' => 'B1');
$this->load->view('test', $data);
$data = array();
$data = array('b' => 'B2');
$this->load->view('test', $data);
}

This will output  A-B1|A-B2|

Again, this is by design.  Look at the source code. Came as a surprise to me too when I first discovered it.

Ok man; i know if you change $b, it will output changed value.

The bug is; we don't call $a again and it must generate error that; it hasn't set.
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#4

$a was set with the first view load. Data passed to any view is cached and is available to any subsequent views that are loaded.
Reply
#5

You can use the below method but that means you will need to set all variables passed in:

PHP Code:
$this->load->clear_vars(); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

You raised an issue on github ... it might have been an idea to raise it here first, to find out if it was a bug or not. We use github for bug tracking, not support.
Reply
#7

(10-12-2016, 06:28 PM)InsiteFX Wrote: You can use the below method but that means you will need to set all variables passed in:

PHP Code:
$this->load->clear_vars(); 

I don't know this rule.
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#8

(10-12-2016, 02:32 PM)dave friend Wrote: $a was set with the first view load.  Data passed to any view is cached and is available to any subsequent views that are loaded.

I want to ask a question:

First model loads view with data.

And then model loads another model.

Second model loads previous view again with another data without clear.

What happens at this time?
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#9

(10-13-2016, 01:43 AM)mertdogan Wrote:
(10-12-2016, 02:32 PM)dave friend Wrote: $a was set with the first view load.  Data passed to any view is cached and is available to any subsequent views that are loaded.

I want to ask a question:

First model loads view with data.

And then model loads another model.

Second model loads previous view again with another data without clear.

What happens at this time?

All data stays, but the newer pieces overwrite older ones.
Reply
#10

(10-13-2016, 02:00 AM)Narf Wrote:
(10-13-2016, 01:43 AM)mertdogan Wrote:
(10-12-2016, 02:32 PM)dave friend Wrote: $a was set with the first view load.  Data passed to any view is cached and is available to any subsequent views that are loaded.

I want to ask a question:

First model loads view with data.

And then model loads another model.

Second model loads previous view again with another data without clear.

What happens at this time?

All data stays, but the newer pieces overwrite older ones.

Hmm. I think there must be a fourth parameter for cache these variables. I have checked previously discussed messages in Github. These caching mechanism is good but user may set this option. May be with config parameter... With this type, it can generate a security hole in complex structures.

Of course; i learned why this happens and what i must do if i want to load same view again. Thx
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB