Welcome Guest, Not a member yet? Register   Sign In
Config file form validation rule groups: doesn't work with controller in sub-folder?
#1

[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(
            'content/edit_page' => array(
                                                array(
                                                    'field' => 'heading',
                                                    'label' => 'Heading',
                                                    'rules' => 'min_length[4]',
                                                      ),
                                                )

        );

and

Code:
$config = array(
            'admin/content/edit_page' => array(
                                                array(
                                                    'field' => 'heading',
                                                    'label' => 'Heading',
                                                    'rules' => 'min_length[4]',
                                                      ),
                                                )

        );

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):
// load the form view
endif;

On the other hand, if I do

Code:
$config = array(
            'pageedit' => array(
                                                array(
                                                    'field' => 'heading',
                                                    'label' => 'Heading',
                                                    'rules' => 'min_length[4]',
                                                      ),
                                                )

        );

and then call the rules explicitly in the controller like this:

Code:
if ($this->form_validation->run('pageedit') == FALSE):
// load the form view
endif;

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?


Messages In This Thread
Config file form validation rule groups: doesn't work with controller in sub-folder? - by El Forum - 01-17-2010, 08:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB