CodeIgniter Forums
Form Validation is_unique issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Form Validation is_unique issue (/showthread.php?tid=61856)



Form Validation is_unique issue - tj_gumis - 05-25-2015

Hi,

To make a long story short. This is the body of the function :
PHP Code:
   public function is_unique($str$field)
 
   {
 
       sscanf($field'%[^.].%[^.]'$table$field);

 
       return isset($this->CI->db)
 
           ? ($this->CI->db->limit(1)->get_where($table, array($field => $str))->num_rows() === 0)
 
           FALSE;
 
   

and it doesn't work in my case. Does not matter what is the real situation :
PHP Code:
       return isset($this->CI->db)... 

throws an error.
If instead of isset() I use is_object() - works fine. What is a reason of such a behavior ?


RE: Form Validation is_unique issue - CroNiX - 05-25-2015

Since CI already has a built-in is_unique validation rule, I'm wondering where you're defining your function?


RE: Form Validation is_unique issue - tj_gumis - 05-25-2015

This is what I am talking about, this function (method), is used by CI3's "is_unique" validation rule and this function is an integrated part of CI3'S form validation library (line 1131).


RE: Form Validation is_unique issue - jenesaisquoi - 09-04-2015

Are you using Modular Extensions (HMVC) ?
Because i have the same issue, and it comes from the '$this->form_validation->CI =& $this;' that we have to add in order to have form_validation working with HMVC.
But the problem with that is that line : $this->CI->db

I'm trying to correct this right now.
I'll tell you when it's working.


RE: Form Validation is_unique issue - jenesaisquoi - 09-04-2015

Finally i simply removed the MY_Form_validation file + $this->form_validation->CI =& $this; inside my class, and the form_validation seems to works well for the moment (+ the is_unique rule working perfectly).


RE: Form Validation is_unique issue - jinbatsu - 10-06-2015

I have the same problem too here, using HMVC.
So if we remove using requiring by HMVC setup:
MY_Form_validation file + $this->form_validation->CI =& $this.
We cannot use custom validation callback, isn't it?
In my case, thats break the flexibility.

Best way is using callback, thats more flexible.