Active records for beginners... - 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: Active records for beginners... (/showthread.php?tid=33592) |
Active records for beginners... - El Forum - 09-01-2010 [eluser]thesocialhacker[/eluser] Hello all, Sorry to bother the forums, but I'm having a bit of a tricky time with the active record and "Objects" it returns... Currently i'd like to retrieve a single records, so i Code: function getmy ($id) { in my controller i Code: $data['row']=$this->backend->getmy($my_id); and in my view i Code: <?php $mydata = $row[0]; ?> My god, i just know that can't be a proper way to go about this... Active records for beginners... - El Forum - 09-01-2010 [eluser]jdav3579[/eluser] <?php $mydata = $row[0]; ?> Think $row is now an object not an array! do <ppre> print_r($row)</pre> Active records for beginners... - El Forum - 09-01-2010 [eluser]cahva[/eluser] You can safely shorten your model method to this: Code: function getmy ($id) row() method always returns only one row so you dont have to use "$q->row(0)". now in the controller: Code: $data['row']=$this->backend->getmy($my_id); In view: Code: <?php echo $row->somefield ?> Active records for beginners... - El Forum - 09-01-2010 [eluser]thesocialhacker[/eluser] thanks cahva! |