Welcome Guest, Not a member yet? Register   Sign In
Putting validation rules in a model?

I'm wanting to put my validation rules in a model, rather than in my controller; that way we keep to the rule of "skinny controllers, fat models" -- I've also seen in other frameworks where they put the rules for validation in the model.

However, I am unable to get it to work.

class News_m extends Model
    public function News_m()

        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');


The above gives me an error:

Quote:Call to a member function set_rules() on a non-object

I've tried putting $this->CI->form_validation and even parent::form_validation->set_rules

Neither of these two work.

Is there another way to fix this issue?


$ci =& get_instance();
$ci->form_validation->set_rules('password', 'Password', 'required');

Sorry to jump on someone else's post, but i to have been wondering how to do this for a while. im assuming theres no way to get the form data directly to the model? it would be case of a controller function that calls the necessary function in the model?

Thanks for your help flaky!

Theme © iAndrew 2016 - Forum software by © MyBB