Validation callbacks into Models |
[eluser]wiredesignz[/eluser]
A nice addition might be for MY_Validation to test isset($parent) and then use $parent =& get_instance() if not valid, so you don't have to pass $CI. First altering run(&$parent = NULL) to prevent errors of course. If someone would like to test for me, I will add it to the wiki if it's successful.
[eluser]beemr[/eluser]
[quote author="wiredesignz" date="1208951222"]so you don't have to pass $CI.[/quote] Actually, I don't think you have to pass anything. Since this library is an extension of CI_Validation, there is already a CI instance, namely $this->CI. I just now replaced $parent with $this->CI and removed the run() argument, and it all worked from my library. I only use this as an extension of the ActiveRecord_Class_Mod, so if you can verify that controller calls will work, I think this extension just got DRY-er.
[eluser]wiredesignz[/eluser]
Yes but the $parent argument allows MY_Validation to work with Modular Extension Models also. Thanks for testing beemr ![]()
[eluser]beemr[/eluser]
OK. Not knowing how this would affect Modular Extension Models, I did just what you asked and the function was successful from my library whether I passed run($this->CI) or not. The new run() opening looks like this: Code: function run(&$parent = NULL) Hope that helps. P.S. Any good links on the merits of an HMVC vs. standard MVC?
[eluser]wiredesignz[/eluser]
Thanks beemr, I will update the wiki to use this. ![]() This original description of the MVC design pattern might interest you. How to use Model-View-Controller (MVC)
[eluser]beemr[/eluser]
CI 1.7 is out now, and the validation lib has been revamped for consistency and clarity. I modified this extension so that I might yet bask in its radiance. So far so good, but since I don't use Modular Extensions, I can't verify whether that connection is still intact. I've kept the $parent variable alive, though it required a slightly awkward tweak. Modular users, please take a look at my note on the wiki, and let us know how it goes. Gracias,
[eluser]lordmontie[/eluser]
Has anyone ever thought of doing something like this? Create a new MY_Form_validation.php library file in your application/libraries folder: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Then in your controller use the validation functions like so: Code: $this->form_validation->set_rules('username', $this->lang->line('field_username'), 'trim|required|valid_email|max_length[250]|username_exists'); OR Code: $this->form_validation->set_rules('invite', $this->lang->line('field_invite'), 'trim|required|alpha_numeric|max_length[50]|strtolower|invite_valid'); |
Welcome Guest, Not a member yet? Register Sign In |