On the one hand, form validation can be considered as part of the application logic and, therefore, belonging to the model.
On the other hand, it directly relates to input coming from the view, and handles display errors, etc. From this angle, it makes sense to add it to the controllers.
Which one is the right MVC approach?
PS my form check actually consists only in writing a list of fields, their rules and passing them to the form check library, which returns true / false whether it passed the check or not.
Example:
$this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Name', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
Should this be placed in a controller or model?
php codeigniter
Click Upvote Apr 13 2018-11-11T00: 00Z
source share