![]() |
MVC - Where should I loop? - 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 - Where should I loop? (/showthread.php?tid=17995) |
MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]überfuzz[/eluser] (Couldn't find anything decent to read about this.) Where should I loop arrays that going to be displayed in the view? View From what I understand there shouldn't be any loops and stuff in the view. Control If I loop through the array here I have to tinker with HTML-tags in the control. MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]oddman[/eluser] If you're iterating through data for display, you put it in the view. Period. MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]überfuzz[/eluser] [quote author="oddman" date="1240405366"]If you're iterating through data for display, you put it in the view. Period.[/quote] So the iteration is done in the control and a string passed to the view? MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]rogierb[/eluser] No, you pass a resultset to your view and iterate in your view. MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]oddman[/eluser] lol no. You assign the data to the view, then you loop through it to display whatever you need. Please read: http://en.wikipedia.org/wiki/Model-view-controller MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]xwero[/eluser] There is a middle ground, loop views. Code: $data['partial'] = ''; Personally i don't like that solution because it calls the view file again and again. I think loops and if else code can be in the view. If you use the alternate syntax for it even designers will be able to figure out what is going on. MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]überfuzz[/eluser] [quote author="xwero" date="1240406444"]There is a middle ground, loop views. Code: $data['partial'] = ''; Personally i don't like that solution because it calls the view file again and again. I think loops and if else code can be in the view. If you use the alternate syntax for it even designers will be able to figure out what is going on.[/quote] I see what you mean. Actually, that was kind of my concern. When I read about MVC it seems that loops, ifs and else are banned in the view part. But its not very handy to be strict with that working with info in arrays. Thanx all!!! MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]oddman[/eluser] [quote author="überfuzz" date="1240406684"]I see what you mean. Actually, that was kind of my concern. When I read about MVC it seems that loops, ifs and else are banned in the view part. But its not very handy to be strict with that working with info in arrays. Thanx all!!![/quote] Hi uberfuzz, This is a safe assumption and I think a common misconception about views. If the conditionals and loops you're using are related to display, it's not an issue. If however, it's concerning logic - then it's in the wrong place. MVC - Where should I loop? - El Forum - 04-22-2009 [eluser]überfuzz[/eluser] [quote author="oddman" date="1240406841"]This is a safe assumption and I think a common misconception about views. If the conditionals and loops you're using are related to display, it's not an issue. If however, it's concerning logic - then it's in the wrong place.[/quote] Right on, thanx! |