CodeIgniter Forums
Getting data back from custom library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Getting data back from custom library (/thread-26155.html)



Getting data back from custom library - El Forum - 01-07-2010

[eluser]pnutz[/eluser]
Hi !

Kind of a newbie question :-)
I've been using codeigniter for some time now and am really enjoying the overview you get when you code your pages.

I currently have a page with a MySQL query on it.
Withing that query, I pass an ID value to a custom library function.

$this->customlib->function($row->id);

The function does it's job correctly... (running a new query and fetching the needed values).
Problem is... how do I pass the newly aquired data from my custom function to the previous function...

a return would not work as this would only pass one value I suppose, and I need a an array with MySQL data coming back to me...


Getting data back from custom library - El Forum - 01-07-2010

[eluser]pnutz[/eluser]
Managed to get this done by loading a view from the custom libraries function.
Don't know if this is the correct way, highly doubt it :-)


Getting data back from custom library - El Forum - 01-07-2010

[eluser]whobutsb[/eluser]
[quote author="pnutz" date="1262893984"]Hi !

Kind of a newbie question :-)
I've been using codeigniter for some time now and am really enjoying the overview you get when you code your pages.

I currently have a page with a MySQL query on it.
Withing that query, I pass an ID value to a custom library function.

$this->customlib->function($row->id);

The function does it's job correctly... (running a new query and fetching the needed values).
Problem is... how do I pass the newly aquired data from my custom function to the previous function...

a return would not work as this would only pass one value I suppose, and I need a an array with MySQL data coming back to me...[/quote]

Your custom lib would look like this:
Code:
class Customlib{
   __construct(){

   }
  
   function($id){
        $CI =& get_instance();
        $CI->load->model('my_model');
     //do something with the ID
     $data = $CI->my_model->mysql_query_function($id) //run your query
     return $data   //finished
   }

}

In your controller. At the end I usually use a print_r or var_dump to check the data returned

Code:
$this->load->library('cusomlib');

$data = $this->customlib->function($row->id);

print_r($data) //Check to see what the data is



Getting data back from custom library - El Forum - 01-07-2010

[eluser]pnutz[/eluser]
thx m8,

looks like a better solution then what I came up with ;-)

I'm gonna try this out later on and I'll bet it will work :-)


Thx again