Welcome Guest, Not a member yet? Register   Sign In
Validation+Filtering
#10

[eluser]alexmiller[/eluser]
I spent some time thinking about this problem and came up with the following solution.

In my model I have the following:

Code:
var $validation_rules['standard'] = array (
  'name' => 'required' // etc. etc.
);

function set_validation_rules($rules = 'standard')
{
  if (is_array($rules)) {
    $this->validation->set_rules($rules) // allow the use of custom rules
  } else {
    $this->validation->set_rules($this->validation_rules[$rules]);
  }
  
}

This allows me to keep all the model things in one place, and then carry out validation in the controller really easily, avoiding the need for rules in the controller except for one-off cases.

Code:
$this->model->set_validation_rules('standard');
$this->validation-run();

Any comments? I'm pretty new to all this.


Messages In This Thread
Validation+Filtering - by El Forum - 09-25-2008, 06:04 PM
Validation+Filtering - by El Forum - 09-25-2008, 06:32 PM
Validation+Filtering - by El Forum - 09-25-2008, 07:05 PM
Validation+Filtering - by El Forum - 09-25-2008, 10:13 PM
Validation+Filtering - by El Forum - 09-25-2008, 11:40 PM
Validation+Filtering - by El Forum - 09-26-2008, 10:10 PM
Validation+Filtering - by El Forum - 09-26-2008, 11:29 PM
Validation+Filtering - by El Forum - 09-27-2008, 03:22 PM
Validation+Filtering - by El Forum - 09-28-2008, 05:16 PM
Validation+Filtering - by El Forum - 09-29-2008, 02:35 PM
Validation+Filtering - by El Forum - 09-29-2008, 02:52 PM
Validation+Filtering - by El Forum - 09-29-2008, 09:46 PM
Validation+Filtering - by El Forum - 09-30-2008, 09:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB