yiisoft/yii — pull request #2282 by pgaultier (2013-04-01 13:35:17+00:00)
Title:  Fixed generation of the HTML class attribute for the data model

Original idea/code by LastDragon-ru

* @see https://github.com/yiisoft/yii/issues/129
* @see https://github.com/yiisoft/yii/pull/2225

Updated files :
* web/form/CForm
* web/helpers/CHml
* web/widgets/CActiveForm
* web/CActiveDataProvider
* CHANGELOG

Added
* sample code in CHtml
* credits to lastDragon-ru in the CHANGELOG
* added shortcut to retrieve postdata
instead of doing :

new methods added :
* get html compliant name : ```CHtml::nameForModel($model)```
* get $_POST data :```CHtml::postDataForModel($model)```

new property added :
* set the filtering method : ```CHtml::$modelNameFilter```

For example (as explained by lastDragon-ru) you can shorten or obfuscate :

```php
CHtml::$modelNameFilter = function($model) {
return dechex(crc32(get_class($model)));
};
```

```php
$htmlModelName = CHtml::nameForModel($model);
if(isset($_POST[htmlModelName]) {
$model->attributes = $_POST[htmlModelName];
// perform actions
// ...
}
```
we can do :

```php
$modelData = CHtml::postDataForModel($model);
if($modelData !== null) {
$model->attributes = $modelData;
// perform actions
// ...
}
```