Welcome Guest, Not a member yet? Register   Sign In
Model best practices
#9

[eluser]CodeIgniteMe[/eluser]
Oh, I'm sorry, I was thinking you meant it like this
Quote:
Code:
class A_Model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    public function set_var1($var1) {
        $this['var1'] = $var1; // using $this as array
        return $this;
    }
    public function set_var2($var2) {
        $this['var2'] = $var2; // using $this as array
        return $this;
    }

    public function create() {
        foreach ($this as $var => $value)
            $this->db->set($var, $value);
        $this->db->insert('table');
        // Should really check if everything went OK, but hey…
    }

}


Messages In This Thread
Model best practices - by El Forum - 07-11-2011, 09:19 PM
Model best practices - by El Forum - 07-11-2011, 10:28 PM
Model best practices - by El Forum - 07-12-2011, 07:03 AM
Model best practices - by El Forum - 07-12-2011, 07:11 PM
Model best practices - by El Forum - 07-12-2011, 07:42 PM
Model best practices - by El Forum - 07-12-2011, 07:50 PM
Model best practices - by El Forum - 07-12-2011, 07:51 PM
Model best practices - by El Forum - 07-12-2011, 08:01 PM
Model best practices - by El Forum - 07-12-2011, 08:08 PM
Model best practices - by El Forum - 07-12-2011, 08:11 PM
Model best practices - by El Forum - 07-12-2011, 08:29 PM
Model best practices - by El Forum - 07-12-2011, 08:30 PM
Model best practices - by El Forum - 07-12-2011, 08:35 PM
Model best practices - by El Forum - 07-12-2011, 08:39 PM
Model best practices - by El Forum - 07-13-2011, 11:12 PM
Model best practices - by El Forum - 07-14-2011, 01:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB