代码改变世界

Yii CActiveForm

2014-06-17 10:20  youxin  阅读(276)  评论(0编辑  收藏  举报

http://www.yiiframework.com/doc/api/1.1/CActiveForm

CActiveForm provides a set of methods that can help to simplify the creation of complex and interactive HTML forms that are associated with data models. 

The 'beginWidget' and 'endWidget' call of CActiveForm widget will render the open and close form tags. Most other methods of CActiveForm are wrappers of the corresponding 'active' methods in CHtml. Calling them in between the 'beginWidget' and 'endWidget' calls will render text labels, input fields, etc. For example, callingCActiveForm::textField would generate an input field for a specified model attribute. 

CActiveForm实际上是对CHtml的封装,,它与Chmtl不同的地方是CActiveForm提供了验证机制,有三种:
   服务器端/客户端/ajax验证。

What makes CActiveForm extremely useful is its support for data validation. CActiveForm supports data validation at three levels:

  • server-side validation: the validation is performed at server side after the whole page containing the form is submitted. If there is any validation error, CActiveForm will render the error in the page back to user.
  • AJAX-based validation: when the user enters data into an input field, an AJAX request is triggered which requires server-side validation. The validation result is sent back in AJAX response and the input field changes its appearance accordingly.
  • client-side validation (available since version 1.1.7): when the user enters data into an input field, validation is performed on the client side using JavaScript. No server contact will be made, which reduces the workload on the server.


All these validations share the same set of validation rules declared in the associated model class. CActiveForm is designed in such a way that all these validations will lead to the same user interface changes and error message content. 

CActiveForm提供了一些方法,这些方法能够方便的去创建一个与数据模型相关联的Form表单。CActiveForm继承自CWidget,所以他需要实现CWidget的init() 和 run() 方法,同时它也实现了一些自己的封装方法。

更多:http://www.cnblogs.com/partoo/archive/2012/04/10/2491126.html