Opinion on best coding practices

I'm still relatively new to CI so this is more of a "what would you do" question.

I'm migrating this system to CI and rewriting some pages, and one in particular in a page with a large calendar, and then along the right side are several ToDo lists for various departments. (This page is a manager overview of tasks each dept is working on.) Not all ToDo lists would show (only if there were items, otherwise they would not display so we didn't have blank ToDo lists.

The old page is a single PHP page that accessed the database and simply displayed a table, such as:

$lines = $db->query("select * from tasklist where (Active=1 or Priority=1)");
while ($line = $db -> fetch_array ($lines))
    if ($acol++==0)
        echo "<table class='calendarsidebargreen'>";
        echo "<tr><th colspan=3>DEPT XYZ LIST</th>";
        echo "</tr>";
    echo "<tr class='calendarsidebar'><td><a href='/task.php?do=edit&i=".$line['>".$line['title']."</a>&nbsp;&nbsp;";
    if ($line['Active']==1) echo "(A)&nbsp;";
    if ($line['Priority']==1) echo "(P)&nbsp;";
    echo "</tr>";
if ($acol>0) echo "</table><P>";

So if we have lines from this department, then display the header, the items, and close the table. We have several such tables.

Now the question is -- what's the best practice in the CI environment.

My first instinct is to just move this code into a model, change the echo statements to a bunch of statements like $html .= where the model function is just building the html, then passing it back to the view and the only thing in the view is a simple echo $html statement. (writing to a variable as it loops through, so the end variable is the HTML display).

But that doesn't seem very "MVC" like because I'm not separating the "view" from the "database". Another option I guess is to move the database read to a model and load up an array with the information, then pass that array to the view and have the view loop through the array. But in that case, I'm simply trading the loop through the table with a loop through an array, which doesn't seem like I'm gaining a whole lot -- plus I'm having to build the array which means I'm looping through all the data TWICE now.

Am I overthinking this? Any recommendations? (Note some of this code didn't format really well in this message, but mostly it came through.)

Messages In This Thread
Opinion on best coding practices - by El Forum - 07-09-2010, 06:07 PM
Opinion on best coding practices - by El Forum - 07-09-2010, 11:25 PM
Opinion on best coding practices - by El Forum - 07-09-2010, 11:29 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.