/** * Save form data * @param $param Request */ public function onSave($param) { try { TTransaction::open('atividade'); // open a transaction /** // Enable Debug logger for SQL operations inside the transaction TTransaction::setLogger(new TLoggerSTD); // standard output TTransaction::setLogger(new TLoggerTXT('log.txt')); // file **/ $this->form->validate(); // validate form data $object = new Sistema(); // create an empty object $data = $this->form->getData(); // get form data as array $object->fromArray((array) $data); // load the object with data $object->store(); // save the object // get the generated id $data->id = $object->id; $this->form->setData($data); // fill form data TTransaction::close(); // close the transaction new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); } catch (Exception $e) { new TMessage('error', $e->getMessage()); // shows the exception error message $this->form->setData($this->form->getData()); // keep form data TTransaction::rollback(); // undo all pending operations } }