function toModel($attr, $value) {
$this->object->on('invalidate', 'onAttributeInvalidate', $this);
$this->object->on('modified', 'onAttributeModified', $this);
$setter = "set{$attr}";
$this->object->$setter($value);
$this->object->un('invalidate', 'onAttributeInvalidate', $this);
$this->object->un('modified', 'onAttributeModified', $this);
}
function onAttributeInvalidate($attr, $value, $object) {
$view = $this->context->getView();
$view->setVar("{$attr}Err", true);
$view->setVar($attr, $value);
$this->errors ++;
}
function onAttributeModified($attr, $value, $object) {
$view = $this->context->getView();
$view->setVar("{$attr}Err", false);
$view->setVar($attr, $value);
}