Config file form validation rule groups: doesn't work with controller in sub-folder? |
[eluser]aidehua[/eluser]
I am trying to use a rule group to set form validation rules in my form_validation config file. I want the rules to be called automatically based on the Controller class name and function - as described under "Associating a Controller Function with a Rule Group" in the user guide. The class is called Content. The function is called edit_page(). However, my Controller file (content.php) lives in a sub-folder (/application/controllers/admin/content.php). According the user guide: Quote:When a rule group is named identically to a controller class/function it will be used automatically when the run() function is invoked from that class/function. But should I include the sub-folder name as well? I tried both Code: $config = array( and Code: $config = array( Neither of them causes the rules to be loaded automatically when I run the form_validation like this in the controller: Code: if ($this->form_validation->run() == FALSE): On the other hand, if I do Code: $config = array( and then call the rules explicitly in the controller like this: Code: if ($this->form_validation->run('pageedit') == FALSE): it works fine. Is it possible to use the automatic-rule-loading feature when your class is in a Controller in sub-folder? If so, what should you put in the array - 'subfolder/class/function' or 'class/function'? And since I've tried both - what might I be doing wrong?
[eluser]baba[/eluser]
it is definitely a bug. form_validation is not parsing correctly the uri. the problem appears when you pass a parameter to your controller e.g. http://.../admin_user/edit/23 then form_validation tries to find a rule group named edit/23 and ... fails.
[eluser]WanWizard[/eluser]
The form validation library uses Code: trim($this->CI->uri->ruri_string(), '/')
[eluser]Unknown[/eluser]
I have the same issue and have some remarks. I think this is not working really well. Or I'm not using it correctly ![]() - the detection of validation rule in $config is case sensitive. So although the Router is not (I can use http://myuri/Member/Signup or http://myuri/member/signup and it will use the right controller and method), the validation is. Which means that if I change the casing, I get an error logged as it doesn't find any validation rule. - "ruri_string()" also includes the method parameter. So it works only with methods without any parameter which is quite limitative. I'm quite new to CodeIgniter and I don't know well its code and all the user cases, but maybe it will work better if Form_Validation->run() was using router->fetch_class() and router->fetch_method() instead of ruri_string(), no ? |
Welcome Guest, Not a member yet? Register Sign In |