![]() |
Help accessing an array returned from a method within the view - 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: Help accessing an array returned from a method within the view (/showthread.php?tid=34335) |
Help accessing an array returned from a method within the view - El Forum - 09-26-2010 [eluser]Unknown[/eluser] Hi I am new to OO style programming and am extending a class in CI. Can anyone tell the best way to access an array returned by a method within the view? I would have thought something like print $this->method_name()['index'] would have worked? But it doesn't seem too. I could always set the results to a variable and access them that way, however I am trying to keep the code in the view simple and this complicates things. Thoughts would be appreciated. Thanks in advance :-) Help accessing an array returned from a method within the view - El Forum - 09-26-2010 [eluser]cahva[/eluser] [quote author="millenniumdarren" date="1285558231"] I could always set the results to a variable and access them that way, however I am trying to keep the code in the view simple and this complicates things. [/quote] Thats the key to keep things simple in a view. Put results in a variable from controller and pass it to the view. For example: Controller Code: function show_user($id=FALSE) Now when you pass that $data to your view, you will have $user variable to work with in there View Code: <h1>Information for user <?php echo $user->name ?></h1> |