1

I have this controller and model:

class MyModel extends CI_Model
{
  public function __construct()
  {
    parent::__construct();
  }
  public function insert($data_array)
  {
    $this->db->insert('table', $data_array);

    if($this->db->affected_rows() == 1) {
      return true;
    }
    return false;    
  }
}


class Panel extends CI_Controller
{
  public function submitPrimer()
  {
    // evaluate data
    $this->load->library('form_validation');
    $this->load->model('MyModel', 'mymodel');  

    // validate, set_rules....

    $data = array(
     'column1'  => $value1;
     // .....
    );

    if($this->mymodel->insert($data)) {
      echo "inserted";
    }
  }
}

Is there any kind of $this->db->show_warnings() in CI. In mysql console there is 'show warnings' command which says for example if you have datatype: float and you insert like this: insert into table (attribute_float) values(''). The proper way would be insert into table (attribute_float) values(NULL).

I also am wondering if 'insert' should go to models. I always assumed only 'select/get' data would go.

broadband
  • 3,266
  • 6
  • 43
  • 73

1 Answers1

0

As much as I'm aware, and from user guide, I don't think that Codeigniter has such a function, for such validation use form_validation library, it's pretty good.

As for insert/edit/delete, they usually go to the model, but it depends on you.

Flakron Bytyqi
  • 3,234
  • 20
  • 20
  • Thank you. Yes the first solution is to prepare data as much as you can. I think there is a 'rule' which says 'you can never trust user input'. For show_warnings I should use: mysql_query("SHOW WARNINGS"); link http://stackoverflow.com/questions/47589/can-i-detect-and-handle-mysql-warnings-with-php – broadband Aug 18 '11 at 08:01