Simple query left join question - MVC - 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: Simple query left join question - MVC (/showthread.php?tid=35938) |
Simple query left join question - MVC - El Forum - 11-16-2010 [eluser]Otemu[/eluser] Hi, Another simple question that I be grateful if anyone can respond. I have a left join query for my news index page, which basically lists various news stories(image, title and intro text), clicking on either the image or title takes you to the corresponding page with the full story. Not all the time however a image is return, as its not a mandatory requirement, so I plan to have a default picture displayed. Currently I have a switch statement on the actual view checking this as shown below: Code: <?php Wasn't sure if this was correct MVC practice to be checking this in the view, or if this should be handled on the actual controller or even the model itself. Cheers Simple query left join question - MVC - El Forum - 11-16-2010 [eluser]mdvaldosta[/eluser] I generally try to keep as much as possible out of the view, including something like that. I want the views to be as simple to redesign as possible. Having said that, I'm not a purist and sometimes thing like that get put into views because it's easier. I think with a pure MVC approach, you'd want to handle that in the controller and spit it out with on foreach that also displays the News stories. Or even putting the image display in it's own helper function would be acceptable, so you can just call it from the view. Simple query left join question - MVC - El Forum - 11-17-2010 [eluser]Otemu[/eluser] Thanks, excellent advice, I think i add to the controller. Simple query left join question - MVC - El Forum - 11-17-2010 [eluser]techgnome[/eluser] I handled my similar situation in the model as part of my select statement: Code: $this->db->select("CASE WHEN ifnull(historylist.picture, '') = '' THEN 'na_01.jpg' ELSE historylist.picture END albumcover"); Not saying it's the best way or only way... just pointing out an alternative. -tg |