RB
Dificuldade em gravar dados na tabela de grupos
Pessoal,
Adicionei mais um campo na tabela de grupos (system_ unit_id), porém ao tentar gravar a unidade do usuário na tabela não grava.
segue abaixo código utilizado:
model SysteGroup
Adicionei mais um campo na tabela de grupos (system_ unit_id), porém ao tentar gravar a unidade do usuário na tabela não grava.
segue abaixo código utilizado:
model SysteGroup
- <?php
- class SystemGroup extends TRecord
- {
- const TABLENAME = 'system_group';
- const PRIMARYKEY = 'id';
- const IDPOLICY = 'max'; // {max, serial}
- private $system_unit;
- /**
- * Constructor method
- */
- public function __construct($id = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct($id, $callObjectLoad);
- parent::addAttribute('name');
- parent::addAttribute('system_unit_id');
- }
- ?>
- <?php
- //método para salvar
- public static function onSave($param)
- {
- try
- {
- // open a transaction with database 'permission'
- TTransaction::open('permission');
- $user = SystemUser::find(TSession::getValue('userid'));
- $unitId = $user->system_unit_id;
- print_r($unitId);
- TTransaction::setLoggerFunction(function ($message) {
- echo $message . '<br>';
- });
- // get the form data into an active record System_group
- $object = new SystemGroup;
- $object->fromArray($param);
- $objetct->system_unit_id = $unitId;
- $object->store();
- $object->clearParts();
- $programs = TSession::getValue('program_list');
- if (!empty($programs))
- {
- foreach ($programs as $program)
- {
- $object->addSystemProgram( new SystemProgram( $program['id'] ) );
- }
- }
- $data = new stdClass;
- $data->id = $object->id;
- TForm::sendData('form_System_group', $data);
- TTransaction::close(); // close the transaction
- new TMessage('info', _t('Record saved')); // shows the success message
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- ?>
Nataniel,
Muito obrigado. era isso mesmo.