![]() |
error extending form_validation library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: error extending form_validation library (/showthread.php?tid=23544) |
error extending form_validation library - El Forum - 10-14-2009 [eluser]redwiz[/eluser] hi all, After months i've decided to migrate some applications from 1.6.3 to 1.7.2. As you know he bigger difference between 1.6 and 1.7 is the form_validation library. In my old ci installation i had a My_validation library to add to CI_validation some custom rules this was my old extended lib: application/libraries/MY_Validation.php <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class MY_Validation extends CI_Validation { function My_Validation() { parent::CI_Validation(); } function unique($str, $field) { $CI =& get_instance(); list($table, $column) = split("\.", $field, 2); $query = $CI->db->query("SELECT COUNT(*) dupe FROM $table WHERE $column = '$str'"); $row = $query->row(); return ($row->dupe > 0) ? FALSE : TRUE; } function greater($str, $field) { if ( ! isset($_POST[$field])) { return FALSE; } return (intval($str) <= intval($_POST[$field])) ? FALSE : TRUE; } } ?> now i made the same thing to extend form_validation class: application/libraries/MY_Form_validation.php class MY_Form_validation extends CI_Form_validation { function My_Form_validation() { parent::CI_Form_validation(); } function unique($str, $field) { $CI =& get_instance(); list($table, $column) = split("\.", $field, 2); $query = $CI->db->query("SELECT COUNT(*) dupe FROM $table WHERE $column = '$str'"); $row = $query->row(); return ($row->dupe > 0) ? FALSE : TRUE; } etc... } In this case what's happen? The lib is correctly loaded, but "run" method fails everytime (with no php errors, obviously) Instead if I ovverride the entire form_validation copying libriaries/Form_validation.php in application/libraries/Form_validation.php and put my method inside the whole library, everything works fine. I've searched the error through the the system with no success... what do you think, this is my fault or maybe a bug? error extending form_validation library - El Forum - 10-14-2009 [eluser]pistolPete[/eluser] Please use [ code ] tags! I guess your constructor should look like this: Code: function My_Form_validation($rules = array()) Since all the constructor does is calling the parent constructor, you could also omit it at all. BTW: You don't need to call get_instance() in function unique(), there is already a class variable ($this->CI) representing the CodeIgniter super object. |