Welcome Guest, Not a member yet? Register   Sign In
Opinion on best coding practices
#2

[eluser]nelson.wells[/eluser]
[quote author="ktwbc" date="1278738456"]
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.
[/quote]

Why populate an array to pass to the view? Why not just pass the result object retrieved from the model?

In the model:
Code:
function get_data()
{
    $where = array(
        "Active" => "1",
        "Priority" => "1"
    );

    $this->db->where($where);
    return $this->db->get("tasklist");
}

Then in the controller
Code:
$data['result'] = $this->Your_model->get_data();
$this->load->view("my_view.php", $data);

Then in the view:
Code:
foreach($result->result() as $row)
{
    //process each row
}

This is MVC, and there is only one loop.


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



Theme © iAndrew 2016 - Forum software by © MyBB