MVC Question: Should I put form validation rules in the controller or model?

前端 未结 9 1601
野性不改
野性不改 2020-12-12 14:41

On one hand form validation could be seen as part of the application logic and therefore belonging in the model.

On the other hand, it deals directly with the input

9条回答
  •  伪装坚强ぢ
    2020-12-12 15:41

    I would say the form validation code should be in the controller (not the model) in most cases.

    Madmartigan put it best in his comment above "Form validation !== Data validation. Not all forms interact with a model"

    Web forms are logically part of the View/Controller part of MVC, since the user interacts with them in the view.

提交回复
热议问题