CodeIgniter Forums
Using Controller variables in library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Using Controller variables in library (/showthread.php?tid=3448)



Using Controller variables in library - El Forum - 10-02-2007

[eluser]Daeli[/eluser]
Hello CI Community,

i think the title says everything. I have a array in my Controller called $data['userdata']. Now i have a user library and i want to use the data from this array too, because its data from the database and this way i will need only one query for all views/libraries.
I tried it with $this->CI->data['userdata'] - But that gave me an error.

Thats the way i load the data into the array.
Code:
foreach($this->db_user->get_userdata() as $row => $value){
                $this->data['userdata'][$row] = $value;
            }
            $this->load->vars($this->data['userdata']);

Are there any suggestions ?

Thanks.


Using Controller variables in library - El Forum - 10-03-2007

[eluser]Daeli[/eluser]
Can anyone help me with this ?


Using Controller variables in library - El Forum - 10-03-2007

[eluser]Michael Wales[/eluser]
Maybe I am misunderstanding, but this seems kind of backwards to me. In most cases, when you have built a user library, you would use the library to retrieve data and pass it off to the controller - not the other way around.

Regardless, you can just pass it as a parameter to the method within your library.