Welcome Guest, Not a member yet? Register   Sign In
Form validation and controllers in subfolders with same name
#1

[eluser]goldpelican[/eluser]
I think I've run into a limitation of using form validation in conjunction with controllers organised in subfolders.

In http://ellislab.com/codeigniter/user-gui...subfolders, a method for organising controllers in subfolders is illustrated - I've used this to organise a frontend and backend to an application, and have ended up with two controllers with the same name (e.g. Member).

In http://ellislab.com/codeigniter/user-gui...ngtoconfig, a method for "Associating a Controller Function with a Rule Group" is illustrated, where validation rules are saved in rule groups, named by the controller/function that uses them, e.g. member/signup.

Now if I have two Member controllers:

application/controllers/frontend/member.php
application/controllers/backend/member.php

...and both have a function named "signup", the form validation runs into a naming clash - I can't create more than one rule group named member/signup - and you can't prefix member with the subfolder name, so frontend/member/signup isn't a valid rule group name.

I've found a workaround though - use the subfolder name in the rule group name, and rather than just call:

if ($this->form_validation->run() == FALSE)

...call the rule group explicitly:

if ($this->form_validation->run('backend/member/signup') == FALSE)

Annoying that the automatic assocation doesn't work, but it works this way.
#2

[eluser]pickupman[/eluser]
I think that is by design. The validation array in your config file is simple a associative array. The array has no way of knowing who is calling it, and if a collusion occurs. I usually call my validation rule explicitly to prevent any confusion. The validation->run method calls the uri string, and checks if a array key exists in the config file. Since you are probably using routing to direct the request to your controllers, the call to the uri string can't determine which controller is running.
#3

[eluser]Ahaenor[/eluser]
[quote author="pickupman" date="1270329819"]I think that is by design. The validation array in your config file is simple a associative array. The array has no way of knowing who is calling it, and if a collusion occurs.[/quote]

Indeed it is. I've encountered the same problem when rtied to use validation array with the controller method that has an argument. So the page has the parameter in url, which maked impossible to map the url to the validation array dimension. I've fixed the problem with the way introduced here.

But still, this mapping is a cool feature, and i hope this trouble will be improved in the future.
#4

[eluser]smithshine[/eluser]
The validation array in your config file is simple a associative array.
When the same problem encountered the same problem when use of validation array
with the controller method that has an argument.
I usually call my validation rule explicitly to prevent any confusion.
#5

[eluser]Ahaenor[/eluser]
Yes, that's what i've said. And i've countered the problem in this way.




Theme © iAndrew 2016 - Forum software by © MyBB