Passing an array (or multiple values) to a Model - 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: Passing an array (or multiple values) to a Model (/showthread.php?tid=21340) |
Passing an array (or multiple values) to a Model - El Forum - 08-06-2009 [eluser]NateL[/eluser] I'm trying to pass two values into a model so that I can run a query that tests against both values. What's the best way to handle this? I've tried these two methods: Controller: Code: $myVar = $this->the_model->the_method($var1, $var2); the_model.php Code: function the_method($var1, $var2){ controller: Code: $theVars = array(); the_model.php Code: function the_method($theVars){ still not quite giving me results I'm after. Thanks for any tips Passing an array (or multiple values) to a Model - El Forum - 08-06-2009 [eluser]bretticus[/eluser] From looking at your code for a sec...I assume you are calling ->get() in your models and just not showing it Shouldn't really matter how the variables get to your model methods so long as they get there. Note that Active Record will chain multiple where() calls together with `AND`. So if your query depends on an `OR`, you will need to just stick the whole `this or that` statement in the where() parameter. That's about as much as anyone can give you without further details. Passing an array (or multiple values) to a Model - El Forum - 08-11-2009 [eluser]Zorancho[/eluser] If you are taking the values from a form, i would suggest you put them into array like this for example: Code: <input type="text" name="user[username]" /> Passing an array (or multiple values) to a Model - El Forum - 08-11-2009 [eluser]jcavard[/eluser] [quote author="NateL" date="1249624378"] the_model.php Code: function the_method($theVars){ This gives you nothing if you don't call get() Also, you are expecting a return from that function when you do this Code: $myVar = $this->the_model->the_method($theVars); so your function should at least call get() and have a 'return' Code: function the_method($theVars){ |