Simple MY_Model library for db methods |
[eluser]Shay Falador[/eluser]
You are completely wrong! I used return false ONLY in 1-row data. Both in get_all and get_all_where I return the query.
[eluser]Phil Sturgeon[/eluser]
Right, so one returns false or data (as I said) and rest return the query object - which should not exist outside of the model. I meant to "I strongly suggest you use Jamies..." to gh0st as for him it will be more logical. For you it is different as you wrote it so for you it makes the most sense.
[eluser]Shay Falador[/eluser]
I see now Phil, thanks for the comments ![]() Well, I made a big change in order to make it simpler, I guess I won't change it anymore. Code: <?php
[eluser]gh0st[/eluser]
Hi. @phil -- Thanks for the answer, I appreciate it. I'll just use sizeof to find out the num_rows() on a query. There's another problem. When I try to run the this->Table->generate($Query_object_goes_here) using the MY_Model, you can't use query. There are several other instances where I need direct access to the query object, the problem is that MY_Model always returns an array, never an object. If we look at Jamie Rumbelow's MY_Model get_all() method: Code: /** It runs the result() method, which then returns an array. There are times when I need to use the object, not an array; for example -- the Table->generate() needs an object, and it won't work on an array. Is there a way where I can grab the result object, without physically hacking Jamie's code? Thanks
[eluser]Phil Sturgeon[/eluser]
[quote author="gh0st" date="1265757223"]Hi. @phil -- Thanks for the answer, I appreciate it. I'll just use sizeof to find out the num_rows() on a query. There's another problem. When I try to run the this->Table->generate($Query_object_goes_here) using the MY_Model, you can't use query. There are several other instances where I need direct access to the query object, the problem is that MY_Model always returns an array, never an object. If we look at Jamie Rumbelow's MY_Model get_all() method: Code: /** It runs the result() method, which then returns an array. There are times when I need to use the object, not an array; for example -- the Table->generate() needs an object, and it won't work on an array. Is there a way where I can grab the result object, without physically hacking Jamie's code? Thanks[/quote] You are getting a little confused here. We are talking about 3 different things: $query: this is the usual name for the database object. Table library really does not want this! $query->result(): This is an array of objects, this is what MY_Model returns. $query->result_array(): This is an array of arrays (a multi-dimensional array) which works with Table in the exact same way as $query->result(). Code: function generate($table_data = NULL) Should be fine. Try debugging a little. :-)
|
Welcome Guest, Not a member yet? Register Sign In |