CodeIgniter Forums
scopes within CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: scopes within CI (/showthread.php?tid=18267)



scopes within CI - El Forum - 04-30-2009

[eluser]ramabodhi[/eluser]
So if in one of my libraries i call $this->CI->inventory = $this->getInv($username)

so far so good.. now i can work with $this->inventory in my views, but when i try to call it in my controllers I get "Message: Undefined property: CI_Loader::$inventory"

How do i taret ci->inventory from within a controller? Do i set the instance to a variable in my constructor, and then act like i'm in one of my libraries?

likewise when i set $this->something in a controller its not accessible in a view... I know the problem here is my syntax and how I'm pointing to the objects, but I'm not sure how to solve it.


scopes within CI - El Forum - 04-30-2009

[eluser]ramabodhi[/eluser]
i also notice the variable is disappearing on a new server request....

in class User i have a function called setInv($user_id), when called it sets $this->inv to a db query result array...

Now if someone clicks the column title i want it to send to '/inventory/sort/'.$field.'/'.$order
and i want the sort method to sort $this->inventory then just return the view...

I'm having a hard time getting scope to work the way i want to, any help is appreciated


scopes within CI - El Forum - 04-30-2009

[eluser]TheFuzzy0ne[/eluser]
It might help us a bit more if you could post some of your code, and perhaps comment on where the unexpected behaviour is.


scopes within CI - El Forum - 04-30-2009

[eluser]ramabodhi[/eluser]
Well i no longer have the code, I solved the problem with a different method, which has brough me to a different problem:
http://ellislab.com/forums/viewthread/113176/

but the issue was that I wanted to sort a db query without having to run the query again, so i tried to set the results to $this->results, then load the view and display $this->results..
(as opposed to $data['results'] = $results; $this->load->view('view', $data)Wink

this way I could keep the result set and sort it by redirecting to the sort method in my controller, which would simply sort $this->results and reaload the view..

I think my problem is that ci gives me the impression of a static environment, but in reality I lose that information on the new server request to the sort method.

i did solve this with sending the results directly to the view with the load view function, but like i said above it has led to a new problem of my css disappearing when theres more than 4 uri segments (though everything works fine).