CodeIgniter Forums
How to return a array from Codeigniter Usermodel - 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: How to return a array from Codeigniter Usermodel (/showthread.php?tid=44477)



How to return a array from Codeigniter Usermodel - El Forum - 08-15-2011

[eluser]Dileep[/eluser]
Hello there ,

I am returning a array from a usermodel.

Code:
function user()
{

.....
.....

$valarray = array('k'=>'z','m'=>'1');
return $valarray();
}

now how can i access this array in a controller ,i know it is a newbie question,please help me.


How to return a array from Codeigniter Usermodel - El Forum - 08-15-2011

[eluser]jblack199[/eluser]
if it's actually in an model you'd do it like this in your controller:

Code:
$this->load->model('model_name');
$whatever = $this->model_name->function();

which theoretically should work fine.

if it's in a helper however, it'd be more like:

Code:
$this->load->helper('helper_name');
$whatever = function();



How to return a array from Codeigniter Usermodel - El Forum - 08-15-2011

[eluser]OliverHR[/eluser]
You can use as normal var/array, like in any other php function.

In a function of your controller:
Code:
function my_function()
{
  $this->load->model('usermodel');

  $array = $this->usermodel->user();

  echo '<pre>';
  print_r($array);
  echo '</pre>';
}



How to return a array from Codeigniter Usermodel - El Forum - 08-15-2011

[eluser]Dileep[/eluser]
Thank you,its worked,+1BRO !!

SOLVED.