[eluser]frist44[/eluser]
I'm trying to slim down the amount of code in my controllers and I've been thinking about form validation. Is it standard practice to load validation rule sets via the model in a fashion like this:
Code:
class Users_member_model extends Model
{
private $_CI;
function __construct()
{
parent::__construct();
$this->_CI = &get;_instance();
$this->_CI->load->library('form_validation');
$this->_init_validation_rules();
}
function _init_validation_rules() {
$this->_CI->form_validation->set_rules('fname', 'first name', 'trim|required');
$this->_CI->form_validation->set_rules('lname', 'last name', 'trim|required');
$this->_CI->form_validation->set_rules('address1', 'address', 'trim|required');
$this->_CI->form_validation->set_rules('city', 'city', 'trim|required');
$this->_CI->form_validation->set_rules('state', 'state', 'trim|required');
$this->_CI->form_validation->set_rules('zip', 'zip', 'trim|required|numeric');
$this->_CI->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
$this->_CI->form_validation->set_rules('emailconf', 'email confirmation', 'trim|required|valid_email|matches[email1]');
$this->_CI->form_validation->set_rules('username', 'username', 'trim|required|min_length[6]');
$this->_CI->form_validation->set_rules('password', 'password', 'trim|required|min_length[6]');
$this->_CI->form_validation->set_rules('passwordconf', 'password confirmation', 'trim|required|min_length[6]|matches[password1]');
}
}
Or is it better to set all the rules in the controller. It just seems to clutter the controller with this many rules.
Thanks!