![]() |
MVC approach to large sets of data with queries from different database tables - 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: MVC approach to large sets of data with queries from different database tables (/showthread.php?tid=40337) |
MVC approach to large sets of data with queries from different database tables - El Forum - 04-05-2011 [eluser]M52 Studios[/eluser] Hey everyone, This has been bothering me for some time, and I honestly don't even know what to search for(topic seems too broad). I really like the MVC pattern approach, and want to abide by it as much as possible while developing apps, but I've been struggling with the following issue for quite some time. I understand querying the data from the database and then sending it over to the view. My question is what do you when there is a need to query another database table, and the query is dependent on what is displayed in the view. Let me explain. For instance. Say I have a table that stores all the clients with some of their specs and I need to display that to a view in a with most information already in that table. Then I come to the point where I need to display their pictures, and the picture reference is stored in a different table. So what is the best way to go about solving this? Do I just call the model to query that table from the view(that is what I have been doing)? Or is there an actual procedure that has already been developed and is widely accepted as the proper way to approach this. pseudo code: foreach customer-query display the information query the database for pictures foreach picture-query display picture I apologize for the lengthy post and very much appreciate your input! -Ilia MVC approach to large sets of data with queries from different database tables - El Forum - 04-05-2011 [eluser]wh1tel1te[/eluser] I don't think there is a right or wrong way to go about this. Taking your example, I personally would pass in a variable to the model method to say whether I want to get picture or not: Code: function get_profile($profile_id, $get_picture=FALSE) This gives you the option of getting the picture or not, all within the one method. MVC approach to large sets of data with queries from different database tables - El Forum - 04-05-2011 [eluser]M52 Studios[/eluser] Thanks for the reply! Let me see if I can explain what I mean a little better ![]() Controller: Get client-query from model Send client-query to view View: Foreach Client-Query display ID Name (Now here's where the problem comes in) based on the ID, I need to query another table to get the client's pictures. So is there a way for me to get all this done in the initial controller and send all the information to the view, without going back and forth? So to have Controller->Model->Controller->View Instead of Controller->Model->Controller->View->Model(to query the pics)->View Does that kind of make sense? |