Revision #8 was created by c@cba on Aug 2, 2012, 2:30:25 PM.
Removed function 'setAttribute()' from class ActiveRecord. Caused problems in my tests. Has problem to do with magic setter methods?
Content
[...]
We usually assign the received user input (=POST variables) to the model before performing other operations (calculations, validaton, saving, etc.).<br>
Therefore we sugges to do the 'unformatting' during the assignment process. This way, after one of the following lines is executed:
```php
$product->attributes = $_POST['Product']; // or ... $product->setAttribute('price', $_POST['Product']['price']); // or ...
$product->setAttributes(array('price'=>$_POST['Product']['price']));
```
`$product->price` will be a valid numerical value and available for further use.
[...]
###2. The 'unformatting' of a number
Extend the CActiveRecord class and override its functions `setAttribute()` and `setAttributes()` to add the 'unformatting' functionality. <br>
For this, create the new file `components/ActiveRecord.php` with the following content:
[...]
}
}
public function setAttribute($name,$value) {
$column = $this->getTableSchema()->getColumn($name); // new
if (stripos($column->dbType, 'decimal') !== false) // new
$value = Yii::app()->format->unformatNumber($value); // new