Welcome Guest, Not a member yet? Register   Sign In
Best approach to implement save method of model.
#1

[eluser]Unknown[/eluser]
Hi!

I have started new CI 2.0 project. And I wonder that is the best approach to implement save method of model?

I thing there are at least 4 ways:

1
Code:
class Brand extends CI_Model
{
    public function save($id, $name, $descr, ....)
    {
        $this->db->query("
              UPDATE  brands SET name =?, descr=?, .... WHERE id=?",
              array($name, $descr, $id,....));
    }
}


2
Code:
class Brand extends CI_Model
{
    public function save($id, $data)
    {
        $this->db->query("
              UPDATE  brands SET name =?, descr=?, .... WHERE id=?",
              array($data['name'], $data['descr'], $id,....));
    }
}


3
Code:
class Brand extends CI_Model
{
    public function save()
    {
        $this->db->query("
              UPDATE  brands SET name =?, descr=?, .... WHERE id=?",
              array($_POST['name'], $_POST['descr'], $_POST['id'],....));
    }
}


4
Code:
class Brand extends CI_Model
{
    public $name;
    public $id;
    public $description;    

    public function save()
    {
        $this->db->query("
              UPDATE  brands SET name =?, descr=?, .... WHERE id=?",
              array($this->name, $this->descr, $this->id,....));
    }
}

Thanks for any advices/thoughts!


Messages In This Thread
Best approach to implement save method of model. - by El Forum - 02-14-2011, 07:35 AM
Best approach to implement save method of model. - by El Forum - 02-14-2011, 08:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB