![]() |
how to pass row( ) data from a model class function to a controller - 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 pass row( ) data from a model class function to a controller (/showthread.php?tid=55927) |
how to pass row( ) data from a model class function to a controller - El Forum - 11-17-2012 [eluser]Rob J Shillito[/eluser] Hi, I have literally started using codeigniter and am still getting my head around how it works. I am creating a simple login for a web app, but not sure how, after I have created a query in a model class, I can get the data back to the controller so I can apply some logic to it. here's my code in my Controller index function: Code: function index() The code at the moment, for testing purposes, is trying to get the fullname value, which is stored in the db. Here's the model code: Code: function checklogin($username, $password){ Could someone enlighten me how you can output each field from the database separately in the Controller class? Very much appreciated ![]() Many thanks Rob Shillito how to pass row( ) data from a model class function to a controller - El Forum - 11-17-2012 [eluser]Rob J Shillito[/eluser] is it not something like this? Code: $fullname = $this->loginscript->checklogin->fullname; thought that doesn't work ![]() Ta how to pass row( ) data from a model class function to a controller - El Forum - 11-17-2012 [eluser]solid9[/eluser] Not tested but try, In your controller: Code: $fullname = $this->loginscript->checklogin('joe', 'pass_me'); Since it is stored as array, you can output for testing like this, [code] echo print_r($fullname); [code] You echo an array inside a controller for testing purpose only. how to pass row( ) data from a model class function to a controller - El Forum - 11-17-2012 [eluser]solid9[/eluser] Once you saw the structure of the array. You will echo or access it's key according to it's structure. If this is not clear to you, please post the structure here of the array, once your done outputting it using print_r(). how to pass row( ) data from a model class function to a controller - El Forum - 11-17-2012 [eluser]Rob J Shillito[/eluser] Thanks very much mate ![]() All working now ![]() Just in case anyone wants the code here is the fix to output the fullname, which is stored in the db. Code: $output = $this->loginscript->checklogin($_POST['username'], $_POST['password']);//pass variables to function Thanks again ![]() how to pass row( ) data from a model class function to a controller - El Forum - 11-17-2012 [eluser]solid9[/eluser] Your welcome. |