Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. $this->form_validation->set_rules('form_field', 'form_label', 'is_unique[table.field]');
  2.  
  3. UNIQUE INDEX `id_aluno` (`id_aluno`, `ano`),
  4.  
  5. $this->form_validation->set_rules('form_field', 'form_label', 'callback_combpk[$pk2]');
  6. public function combpk($pk1, $pk2)
  7. {
  8. $this->db->where('field1', $pk1);
  9. $this->db->where('field2', $pk2);
  10. $result = $this->db->get('table');
  11. if($result->num_rows() > 0)
  12. {
  13. $this->form_validation->set_message('combpk','something'); // set your message
  14. return false;
  15. }
  16. else{ return true;}
  17.  
  18. }
  19.  
  20. $last_id = $this->model->set();
  21. if ($last_id === FALSE)
  22. if ($this->db->_error_number() == 1062)
  23. $this->data['message_error'] = 'Not unique.';
  24. else
  25. $this->data['message_error'] = 'Database error.';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement