Welcome Guest, Not a member yet? Register   Sign In
You must use the SET method to update an entry
#11

[eluser]ducuytran[/eluser]
I've got the same bug. My case:
Code:
//something_model.php
class Something_Model extends Model {
    private $table;
    
    function __construct() {
        parent::Model();
        $this->table = SomethingEntity::get_table();
    }
    
    public function insert(SomethingEntity $sobj) {
        return $this->db->insert($this->table, $sobj);
    }
}

class SomethingEntity {
    private static $table = 'something';
    private $id;
    private $name;
    
    public static function get_table() {
        return self::$table;
    }
    
    public function __get($name)
    {
        $method = 'get_' . $name;
        if (!method_exists($this, $method))
            throw new Exception($method . '(): Invalid ' . self::$table . ' property');
        return $this->$method();
    }
    
    public function __set($name, $value)
    {
        $method = 'set_' . $name;
        if (!method_exists($this, $method))
            throw new Exception($method . '(): Invalid ' . self::$table . ' property');
        return $this->$method($value);
    }
    
    public function set_id($value) {
        $this->id = $value;
    }
    
    public function get_id() {
        return $this->id;
    }
    
    public function set_name($value) {
        $this->name = $value;
    }
    
    public function get_name() {
        return $this->name;
    }
}

//In somethingcp.php
class SomethingCP extends Controller {
    function __construct() {
        parent::Controller();
        $this->load->model('something_model');
    }
    
    function index() {
        $this->_check_request();
    }

    function _check_request() {
        if (isset($_POST['something-title'])) {
            $sobj = new SomethingEntity();
            $sobj->name = $this->input->post('something-title');
            return $this->something_model->insert($sobj);
        }
        return false;
    }
}
I found out that the $sobj->id caused this bug, though it was not set any value.

Code:
//Within DB_active_rec.php from line 1150
    function insert($table = '', $set = NULL)
    {    
        if ( ! is_null($set))
        {
            $this->set($set);
        }
    
        if (count($this->ar_set) == 0)
        {
            if ($this->db_debug)
            {
                return $this->display_error('db_must_use_set'); //Throws: You must use the "set" method to update an entry.
            }
            return FALSE;
        }
        ...
    }
This insert() method misundertands the id has a value (though it's null), beside that, in my DB, id field of something table was set 'auto_increment'.

So, my solutions:
_ Customize the set() method of class CI_DB_active_record
_ or use an Array (without ['id']) as param for insert() method within Something_Model class.

You guys have any ideas?


Messages In This Thread
You must use the SET method to update an entry - by El Forum - 07-11-2007, 11:23 AM
You must use the SET method to update an entry - by El Forum - 07-17-2007, 05:41 PM
You must use the SET method to update an entry - by El Forum - 09-08-2008, 07:03 PM
You must use the SET method to update an entry - by El Forum - 10-16-2008, 06:51 PM
You must use the SET method to update an entry - by El Forum - 10-16-2008, 09:00 PM
You must use the SET method to update an entry - by El Forum - 10-16-2008, 10:01 PM
You must use the SET method to update an entry - by El Forum - 04-28-2009, 05:24 AM
You must use the SET method to update an entry - by El Forum - 12-20-2009, 11:40 AM
You must use the SET method to update an entry - by El Forum - 12-20-2009, 11:44 AM
You must use the SET method to update an entry - by El Forum - 03-02-2010, 07:55 AM
You must use the SET method to update an entry - by El Forum - 11-30-2010, 02:36 AM
You must use the SET method to update an entry - by El Forum - 03-16-2011, 02:56 AM
You must use the SET method to update an entry - by El Forum - 07-27-2011, 06:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB