![]() |
functions in views - 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: functions in views (/showthread.php?tid=57893) |
functions in views - El Forum - 04-23-2013 [eluser]Unknown[/eluser] Hello, I hear a lot of people banging on about how calling functions inside views is bad practice. What if I had a foreach loop that echo'd out some data but wanted to call a function with some of that data. e.g <?php foreach ($posts as $post) { echo $post->title; echo $post->content; time_difference($post->timestamp); } ?> Notice the time_difference function? How would I do that without calling it in the function? functions in views - El Forum - 04-23-2013 [eluser]Aken[/eluser] If all your time_difference() function does is take the timestamp and turn it into something like a human-friendly time, then you're fine. That isn't a big deal, because it's a presentational thing. You'll get some people who strictly say NO, but it's not a hard-written rule. Just don't go doing a bunch of logic stuff in your views, that's what you should be avoiding. |