Welcome Guest, Not a member yet? Register   Sign In
Odd object-oriented ramifications...
#1

[eluser]tmcw[/eluser]
Been noticing a weird pattern in CI.

I have a controller, and some content that will be the same over a few different pages (methods). So I have that in a different method, which runs a query, throws the result into $vars['events'] = $r. Then I load that into a template, like so: $o = $this->load->view('/event/list', $vars,true); and return $o.

The weird part is that, after I run this method in another controller ($data['event_list'] = $this->event_list()Wink The variable $data['events'] holds the same data as $vars['events'] did, and running a query that returns false doesn't replace that data with false.

Now, maybe this is intended behavior, but it seems to be rather unpredictable when you think of encapsulation and unintended consequences... there isn't a way to load a template with data, and then load another without the second being affected by the first?

Any ideas here?
#2

[eluser]coolfactor[/eluser]
You've got two separate variables:

Code:
$vars['events']
$data['event_list']

Not quite sure what you're asking...

Can you provide actual code?
#3

[eluser]tmcw[/eluser]
Here's the control flow:

Let's say I call

main_view();

which calls another controller function (same controller) like this:

$data['event_list'] = $this->event_list();

Within that controller, event_list(), I run a query and load the data into $var like so:

$vars['events'] = $r

... and I throw the results into a template

------- And then I'm done with the event_list function, and back in the main_view() function, when I render another view, for whatever reason, the data that I had put into $vars is appended to the variables accessable when I render another template.
#4

[eluser]coolfactor[/eluser]
Still not clear. Some real code would be useful. It speaks for itself. Smile




Theme © iAndrew 2016 - Forum software by © MyBB