是否应在yii应用程序中以所有形式使用表单模型?

What wrong is it in creating a simple form tag in html to hold a small form whose validation can be written easily instead of creating a form model to hold the rules and labels?

Consider this before abandoning the form model. The form model does a lot of things for you. Some of these things will take a lot of effort to build for yourself. Here is a quick list:

  • It maintains code consistency within your app
  • It maintains UI consistency for the user
  • It provides validation
  • It provides Error Handling
  • It helps prevent certain attacks like SQL Injection
  • It can help prevent other attacks if you turn on CSRF tagging
  • Client side validation is built in and can be enabled with a configuration
  • Ajax functionality is built in and can be enabled with a configuration

There are a lot of things you are giving up. Even for a simple form. And those things go beyond validation and HTML formatting.

You can choose a simplest way, it will not be wrong.

FormModels should help you to organize a lot of validation rules, scenarios and other. If creation of FormModel will take more effort than just write validation in controller, this isn't case for FormModel.