Conheça as melhorias da versão 8.0, 8.1, 8.2!
Clique aqui para saber mais
Problema ao carregar dados em datagrid de um form mestre/detalhe Boa tarde a todos, Estou com um problema ao carregar os dados em um datagrid de um formulário mestre/detalhe para edição de cadastros. O formulário mestre carrega os dados normalmente, a dificuldade está em carregar os dados no datagrid do formulário de detalhe. Alguém poderia me ajudar? Desde já agradeço a atenção. Segue código: FORMULÁRIO MESTRE DETALHE: ...
ET
Problema ao carregar dados em datagrid de um form mestre/detalhe  
Boa tarde a todos,
Estou com um problema ao carregar os dados em um datagrid de um formulário mestre/detalhe para edição de cadastros.
O formulário mestre carrega os dados normalmente, a dificuldade está em carregar os dados no datagrid do formulário de detalhe.

Alguém poderia me ajudar? Desde já agradeço a atenção.

Segue código:

FORMULÁRIO MESTRE DETALHE:
 
  1. <?php
  2. /**
  3. * ClienteForm Form
  4. * @author <your name here>
  5. */
  6. class ClienteForm extends TPage
  7. {
  8. protected $form; // form
  9. use adianti\base\AdiantiMasterDetailTrait;
  10. /**
  11. * Form constructor
  12. * @param $param Request
  13. */
  14. public function __construct( $param )
  15. {
  16. parent::__construct();
  17. $this->form = new BootstrapFormBuilder('list_Cliente');
  18. $this->form->setFormTitle('Cliente');
  19. // master fields
  20. $id = new TEntry('id');
  21. $codigo_cliente = new TEntry('codigo_cliente');
  22. $data_cadastro = new TDate('data_cadastro');
  23. $nome = new TEntry('nome');
  24. $sexo_id = new TDBCombo('sexo_id', 'microerp', 'Sexo', 'id', '{sexo}','id asc');
  25. $rg = new TEntry('rg');
  26. $orgao_expeditor = new TEntry('orgao_expeditor');
  27. $cpf = new TEntry('cpf');
  28. $profissao = new TEntry('profissao');
  29. $religiao = new TEntry('religiao');
  30. $estado_civil = new TEntry('estado_civil');
  31. $data_nascimento = new TDate('data_nascimento');
  32. $idade = new TEntry('idade');
  33. $data_falecimento = new TDate('data_falecimento');
  34. $telefone_um = new TEntry('telefone_um');
  35. $telefone_dois = new TEntry('telefone_dois');
  36. $celular = new TEntry('celular');
  37. $uf_id = new TDBUniqueSearch('uf_id', 'microerp', 'Cidade', 'id', 'uf','id asc' );
  38. $cidade_id = new TDBUniqueSearch('cidade_id', 'microerp', 'Cidade', 'id', 'nome','id asc' );
  39. $area_id = new TDBCombo('area_id', 'microerp', 'Area', 'id', '{area}','id asc');
  40. $bairro_id = new TDBUniqueSearch('bairro_id', 'microerp', 'Cidade', 'id', 'bairro','id asc' );
  41. $numero = new TEntry('numero');
  42. $cep = new TEntry('cep');
  43. $referencia = new TEntry('referencia');
  44. $complemento = new TEntry('complemento');
  45. $data_admissao = new TDate('data_admissao');
  46. $data_carencia = new TDate('data_carencia');
  47. $primeiro_vencimento = new TDate('primeiro_vencimento');
  48. // detail fields
  49. $dependente_nome = new TEntry('dependente_nome');
  50. $dependente_data_admissao = new TDate('dependente_data_admissao');
  51. $dependente_data_carencia = new TDate('dependente_data_carencia');
  52. $status_dependente_id = new TDBCombo('status_dependente_id', 'microerp', 'StatusDependente', 'id', '{status_dependente}','id asc');
  53. $dependente_id = new THidden('dependente_id');
  54. $nome->addValidation('Nome', new TRequiredValidator());
  55. $sexo_id->addValidation('Sexo', new TRequiredValidator());
  56. $rg->addValidation('RG', new TRequiredValidator());
  57. $cpf->addValidation('CPF', new TRequiredValidator());
  58. $idade->addValidation('Idade', new TRequiredValidator());
  59. $uf_id->addValidation('UF', new TRequiredValidator());
  60. $cidade_id->addValidation('Cidade', new TRequiredValidator());
  61. $area_id->addValidation('Area', new TRequiredValidator());
  62. $bairro_id->addValidation('Bairro', new TRequiredValidator());
  63. $cep->addValidation('CEP', new TRequiredValidator());
  64. $uf_id->setMinLength(1);
  65. $cidade_id->setMinLength(2);
  66. $bairro_id->setMinLength(2);
  67. $cpf->setMaxLength(14);
  68. $rg->setMaxLength(20);
  69. $cep->setMaxLength(9);
  70. $telefone_um->setMaxLength(11);
  71. $telefone_dois->setMaxLength(11);
  72. $celular->setMaxLength(11);
  73. $numero->setMaxLength(4);
  74. $data_cadastro->setDatabaseMask('yyyy-mm-dd');
  75. $data_nascimento->setDatabaseMask('yyyy-mm-dd');
  76. $data_falecimento->setDatabaseMask('yyyy-mm-dd');
  77. $data_admissao->setDatabaseMask('yyyy-mm-dd');
  78. $data_carencia->setDatabaseMask('yyyy-mm-dd');
  79. $primeiro_vencimento->setDatabaseMask('yyyy-mm-dd');
  80. $data_cadastro->setMask('dd/mm/yyyy');
  81. $data_nascimento->setMask('dd/mm/yyyy');
  82. $data_falecimento->setMask('dd/mm/yyyy');
  83. $data_admissao->setMask('dd/mm/yyyy');
  84. $data_carencia->setMask('dd/mm/yyyy');
  85. $primeiro_vencimento->setMask('dd/mm/yyyy');
  86. $dependente_data_admissao->setDatabaseMask('yyyy-mm-dd');
  87. $dependente_data_carencia->setDatabaseMask('yyyy-mm-dd');
  88. $dependente_data_admissao->setMask('dd/mm/yyyy');
  89. $dependente_data_carencia->setMask('dd/mm/yyyy');
  90. $id->setEditable(false);
  91. $id->setSize(100);
  92. $codigo_cliente->setSize('72%');
  93. $data_cadastro->setSize('72%');
  94. $nome->setSize('72%');
  95. $sexo_id->setSize('10%');
  96. $rg->setSize('72%');
  97. $orgao_expeditor->setSize('70%');
  98. $cpf->setSize('72%');
  99. $profissao->setSize('70%');
  100. $religiao->setSize('72%');
  101. $estado_civil->setSize('70%');
  102. $data_nascimento->setSize('70%');
  103. $idade->setSize('70%');
  104. $data_falecimento->setSize('70%');
  105. $telefone_um->setSize('70%');
  106. $telefone_dois->setSize('70%');
  107. $celular->setSize('70%');
  108. $uf_id->setSize('70%');
  109. $cidade_id->setSize('72%');
  110. $area_id->setSize('72%');
  111. $bairro_id->setSize('72%');
  112. $numero->setSize('70%');
  113. $complemento->setSize('70%');
  114. $cep->setSize('70%');
  115. $referencia->setSize('70%');
  116. $data_admissao->setSize('70%');
  117. $data_carencia->setSize('70%');
  118. $primeiro_vencimento->setSize('70%');
  119. $id->setEditable(FALSE);
  120. $status_dependente_id->setSize(100);
  121. $dependente_nome->setSize('70%');
  122. $dependente_data_admissao->setSize('70%');
  123. $dependente_data_carencia->setSize('70%');
  124. $status_dependente_id->setSize('70%');
  125. // master fields
  126. $this->form->addFields([new TLabel('Id:')],[$id]);
  127. $this->form->addFields([new TLabel('Codigo Cliente:')],[$codigo_cliente], [new TLabel('Data Cadastro:')],[$data_cadastro]);
  128. $this->form->addFields([new TLabel('Nome:', '#ff0000')],[$nome], [new TLabel('Sexo:', '#ff0000')],[$sexo_id]);
  129. $this->form->addFields([new TLabel('RG:', '#ff0000')],[$rg], [new TLabel('Orgão Expeditor:')],[$orgao_expeditor]);
  130. $this->form->addFields([new TLabel('CPF:', '#ff0000')],[$cpf], [new TLabel('Profissão:')],[$profissao]);
  131. $this->form->addFields([new TLabel('Religião:')],[$religiao], [new TLabel('Estado Civil:')],[$estado_civil]);
  132. $this->form->addFields([new TLabel('Data Nascimento:')],[$data_nascimento], [new TLabel('Idade:', '#ff0000')],[$idade], [new TLabel('Data Falecimento:')],[$data_falecimento]);
  133. $this->form->addFields([new TLabel('Telefone 1:')],[$telefone_um], [new TLabel('Telefone 2:')],[$telefone_dois], [new TLabel('Celular:')],[$celular]);
  134. $this->form->addFields([new TLabel('UF:', '#ff0000')],[$uf_id], [new TLabel('Cidade:', '#ff0000')],[$cidade_id], [new TLabel('Área:', '#ff0000')],[$area_id]);
  135. $this->form->addFields([new TLabel('Bairro:', '#ff0000')],[$bairro_id], [new TLabel('Número:')],[$numero], [new TLabel('CEP:', '#ff0000')],[$cep]);
  136. $this->form->addFields([new TLabel('Complemento:')],[$complemento], [new TLabel('Referência:')],[$referencia]);
  137. $this->form->addFields([new TLabel('Data Admissão:')],[$data_admissao], [new TLabel('Data Carência:')],[$data_carencia], [new TLabel('Primeiro Vencimento:')],[$primeiro_vencimento]);
  138. // detail fields
  139. $this->form->addContent([new TFormSeparator('Dependentes', '#333333', '18', '#eeeeee')]);
  140. //$this->form->addFields([new TLabel('Id:')],[$id]);
  141. $this->form->addFields([new TLabel('Nome:')],[$dependente_nome]);
  142. $this->form->addFields([new TLabel('Data Admissão:')],[$dependente_data_admissao], [new TLabel('Data Carência:')],[$dependente_data_carencia]);
  143. $this->form->addFields([new TLabel('Status do Dependente:')],[$status_dependente_id]);
  144. $this->form->addFields([$dependente_id]);
  145. // add button
  146. $add_dependente = new TButton('add_dependente');
  147. $add_dependente->setAction(new TAction(array($this, 'onAddDependente')), 'Adicionar');
  148. $add_dependente->setImage('fa:plus #51c249');
  149. $this->form->addFields([$add_dependente]);
  150. // detail datagrid
  151. $this->item_dependente_list = new BootstrapDatagridWrapper(new TQuickGrid);
  152. $this->item_dependente_list->style = 'width:100%';
  153. $this->item_dependente_list->class .= ' table-bordered';
  154. $this->item_dependente_list->disableDefaultClick();
  155. $this->item_dependente_list->addQuickColumn('', 'edit', 'left', 50);
  156. $this->item_dependente_list->addQuickColumn('', 'delete', 'left', 50);
  157. $col_dependente_id = $this->item_dependente_list->addQuickColumn('Dependente', 'dependente_nome', 'left');
  158. $col_data_admissao = $this->item_dependente_list->addQuickColumn('Data Admissão', 'dependente_data_admissao', 'left');
  159. $col_data_carencia = $this->item_dependente_list->addQuickColumn('Data Carência', 'dependente_data_carencia', 'right');
  160. $col_status_dependente = $this->item_dependente_list->addQuickColumn('Status Dependente', 'status_dependente_id', 'right');
  161. $this->item_dependente_list->createModel();
  162. $this->form->addContent([$this->item_dependente_list]);
  163. // create the form actions
  164. $this->form->addAction('Salvar', new TAction([$this, 'onSave']), 'fa:floppy-o')->addStyleClass('btn-primary');
  165. $this->form->addAction('Limpar formulário', new TAction([$this, 'onClear']), 'fa:eraser #dd5a43');
  166. // vertical box container
  167. $container = new TVBox;
  168. $container->style = 'width: 100%';
  169. $container->class = 'form-container';
  170. $container->add(new TXMLBreadCrumb('menu.xml', 'ClienteList'));
  171. $container->add($this->form);
  172. parent::add($container);
  173. }
  174. /**
  175. * Adiciona dependente ao cliente
  176. * @param $param Request
  177. */
  178. public function onAddDependente( $param )
  179. {
  180. try
  181. {
  182. $data = $this->form->getData();
  183. if(!$data->dependente_nome)
  184. {
  185. throw new Exception(AdiantiCoreTranslator::translate('The field ^1 is required', 'Dependente'));
  186. }
  187. $item_dependente_items = TSession::getValue('item_dependente_items');
  188. $key = !empty($data->dependente_id) ? $data->dependente_id : uniqid();
  189. $fields = [];
  190. $fields['dependente_nome'] = $data->dependente_nome;
  191. $fields['dependente_data_admissao'] = $data->dependente_data_admissao;
  192. $fields['dependente_data_carencia'] = $data->dependente_data_carencia;
  193. $fields['status_dependente_id'] = $data->status_dependente_id;
  194. $item_dependente_items[ $key ] = $fields;
  195. TSession::setValue('item_dependente_items', $item_dependente_items);
  196. // limpa os campos do item do dependente
  197. $data->dependente_nome = '';
  198. $data->dependente_data_admissao = '';
  199. $data->dependente_data_carencia = '';
  200. $data->status_dependente_id = '';
  201. $data->dependente_id = '';
  202. $this->form->setData($data);
  203. $this->onReload( $param );
  204. }
  205. catch (Exception $e)
  206. {
  207. $this->form->setData( $this->form->getData());
  208. new TMessage('error', $e->getMessage());
  209. }
  210. }
  211. /**
  212. * Recarrega tudo
  213. * @param $param Request
  214. */
  215. public function onReload($params = null)
  216. {
  217. $this->loaded = TRUE;
  218. $this->onReloadDependenteItemDependente($params);
  219. }
  220. /**
  221. * Recarrega itens do dependente
  222. * @param $param Request
  223. */
  224. public function onReloadDependenteItemDependente( $param )
  225. {
  226. $items = TSession::getValue('item_dependente_items');
  227. $this->item_dependente_list->clear();
  228. if($items)
  229. {
  230. $cont = 1;
  231. foreach ($items as $key => $item)
  232. {
  233. $rowItem = new StdClass;
  234. $action_del = new TAction(array($this, 'onDeleteItemDependente'));
  235. $action_del->setParameter('item_dependente_id_row_id', $key);
  236. $action_edi = new TAction(array($this, 'onEditItemDependente'));
  237. $action_edi->setParameter('item_dependente_id_row_id', $key);
  238. $button_del = new TButton('delete_item_dependente'.$cont);
  239. $button_del->class = 'btn btn-default btn-sm';
  240. $button_del->setAction($action_del, '');
  241. $button_del->setImage('fa:trash-o');
  242. $button_del->setFormName($this->form->getName());
  243. $button_edi = new TButton('edit_item_dependente'.$cont);
  244. $button_edi->class = 'btn btn-default btn-sm';
  245. $button_edi->setAction($action_edi, '');
  246. $button_edi->setImage('bs:edit');
  247. $button_edi->setFormName($this->form->getName());
  248. $rowItem->edit = $button_edi;
  249. $rowItem->delete = $button_del;
  250. $rowItem->status_dependente_id = '';
  251. if (isset($item['status_dependente_id']) && $item['status_dependente_id'])
  252. {
  253. TTransaction::open('microerp');
  254. $statusdependente = StatusDependente::find($item['status_dependente_id']);
  255. $rowItem->status_dependente_id = $statusdependente->render('{status_dependente}');
  256. TTransaction::close();
  257. }
  258. $rowItem->dependente_nome = isset($item['dependente_nome']) ? $item['dependente_nome'] : '';
  259. $rowItem->dependente_data_admissao = isset($item['dependente_data_admissao']) ? $item['dependente_data_admissao'] : '';
  260. $rowItem->dependente_data_carencia = isset($item['dependente_data_carencia']) ? $item['dependente_data_carencia'] : '';
  261. $rowItem->status_dependente_id = isset($item['status_dependente_id']) ? $item['status_dependente_id'] : '';
  262. $this->item_dependente_list->addItem($rowItem);
  263. $cont ++;
  264. }
  265. }
  266. }
  267. /**
  268. * Edita item dependente
  269. * @param $param Request
  270. */
  271. public function onEditItemDependente( $param )
  272. {
  273. $data = $this->form->getData();
  274. // read session items
  275. $items = TSession::getValue('item_dependente_items');
  276. // get the session item
  277. $item = $items[$param['item_dependente_id_row_id']];
  278. $data->dependente_nome = $item['dependente_nome'];
  279. $data->dependente_data_admissao = $item['dependente_data_admissao'];
  280. $data->dependente_data_carencia = $item['dependente_data_carencia'];
  281. $data->status_dependente_id = $item['status_dependente_id'];
  282. $data->dependente_id = $param['item_dependente_id_row_id'];
  283. // fill product fields
  284. $this->form->setData( $data );
  285. $this->onReload( $param );
  286. }
  287. /**
  288. * Exclui item do pedido
  289. * @param $param Request
  290. */
  291. public function onDeleteItemDependente( $param )
  292. {
  293. $data = $this->form->getData();
  294. $data->dependente_nome = '';
  295. $data->dependente_data_admissao = '';
  296. $data->dependente_data_carencia = '';
  297. $data->status_dependente_id = '';
  298. $this->form->setData( $data );
  299. // read session items
  300. $items = TSession::getValue('item_dependente_items');
  301. // delete the item from session
  302. unset($items[$param['item_dependente_id_row_id']]);
  303. TSession::setValue('item_dependente_items', $items);
  304. $this->onReload( $param );
  305. }
  306. /**
  307. * Limpa formulário
  308. * @param $param Request
  309. */
  310. public function onClear( $param )
  311. {
  312. $this->form->clear();
  313. TSession::setValue('item_dependente_items', null);
  314. $this->onReload();
  315. }
  316. /**
  317. * Salva registro
  318. * @param $param Request
  319. */
  320. public function onSave($param = null)
  321. {
  322. try
  323. {
  324. TTransaction::open('microerp');
  325. $this->form->validate();
  326. $data = $this->form->getData();
  327. $object = new Cliente;
  328. $object->fromArray( (array) $data);
  329. $object->store();
  330. $this->storeItems('Dependente', 'cliente_id', $object, 'item_dependente',
  331. function($masterObject, $detailObject) {
  332. });
  333. $object->store();
  334. $data->id = $object->id;
  335. $this->form->setData($data);
  336. TTransaction::close();
  337. new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
  338. }
  339. catch (Exception $e)
  340. {
  341. new TMessage('error', $e->getMessage());
  342. $this->form->setData( $this->form->getData() );
  343. TTransaction::rollback();
  344. }
  345. }
  346. /**
  347. * Edita formulário
  348. * @param $param Request
  349. */
  350. public function onEdit( $param )
  351. {
  352. try
  353. {
  354. if (isset($param['key']))
  355. {
  356. $key = $param['key'];
  357. TTransaction::open('microerp');
  358. $object = new Cliente($key);
  359. $this->loadItems('Dependente', 'cliente_id', $object, 'item_dependente');
  360. $this->form->setData($object);
  361. $this->onReload();
  362. TTransaction::close();
  363. }
  364. else
  365. {
  366. $this->form->clear();
  367. }
  368. }
  369. catch (Exception $e)
  370. {
  371. new TMessage('error', $e->getMessage());
  372. TTransaction::rollback();
  373. }
  374. }
  375. /**
  376. * Exibe a página
  377. * @param $param Request
  378. */
  379. public function show()
  380. {
  381. if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  382. {
  383. $this->onReload( func_get_arg(0) );
  384. }
  385. parent::show();
  386. }
  387. }
  388. ?>


MODEL DA TABELA CLIENTE:
 
  1. <?php
  2. class Cliente extends TRecord
  3. {
  4. const TABLENAME = 'cliente';
  5. const PRIMARYKEY = 'id';
  6. const IDPOLICY = 'serial'; // {max, serial}
  7. /**
  8. * Constructor method
  9. */
  10. public function __construct($id = NULL, $callObjectLoad = TRUE)
  11. {
  12. parent::__construct($id, $callObjectLoad);
  13. parent::addAttribute('codigo_cliente');
  14. parent::addAttribute('data_cadastro');
  15. parent::addAttribute('nome');
  16. parent::addAttribute('sexo_id');
  17. parent::addAttribute('rg');
  18. parent::addAttribute('orgao_expeditor');
  19. parent::addAttribute('cpf');
  20. parent::addAttribute('profissao');
  21. parent::addAttribute('religiao');
  22. parent::addAttribute('estado_civil');
  23. parent::addAttribute('data_nascimento');
  24. parent::addAttribute('idade');
  25. parent::addAttribute('data_falecimento');
  26. parent::addAttribute('telefone_um');
  27. parent::addAttribute('telefone_dois');
  28. parent::addAttribute('celular');
  29. parent::addAttribute('uf_id');
  30. parent::addAttribute('cidade_id');
  31. parent::addAttribute('bairro_id');
  32. parent::addAttribute('numero');
  33. parent::addAttribute('complemento');
  34. parent::addAttribute('cep');
  35. parent::addAttribute('referencia');
  36. parent::addAttribute('data_admissao');
  37. parent::addAttribute('data_carencia');
  38. parent::addAttribute('primeiro_vencimento');
  39. parent::addAttribute('area_id');
  40. }
  41. /**
  42. * Method set_status_dependente
  43. * Sample of usage: $var->area = $object;
  44. * @param $object Instance of Cidade
  45. */
  46. public function set_area(Area $object)
  47. {
  48. $this->area = $object;
  49. $this->area_id = $object->id;
  50. }
  51. /**
  52. * Method get_status_dependente
  53. * Sample of usage: $var->area->attribute;
  54. * @returns Cidade instance
  55. */
  56. public function get_area()
  57. {
  58. // loads the associated object
  59. if (empty($this->area))
  60. $this->area = new Area($this->area_id);
  61. // returns the associated object
  62. return $this->area;
  63. }
  64. /**
  65. * Method set_status_dependente
  66. * Sample of usage: $var->sexo = $object;
  67. * @param $object Instance of Cidade
  68. */
  69. public function set_sexo(Sexo $object)
  70. {
  71. $this->sexo = $object;
  72. $this->sexo_id = $object->id;
  73. }
  74. /**
  75. * Method get_status_dependente
  76. * Sample of usage: $var->sexo->attribute;
  77. * @returns Cidade instance
  78. */
  79. public function get_sexo()
  80. {
  81. // loads the associated object
  82. if (empty($this->sexo))
  83. $this->sexo = new Sexo($this->sexo_id);
  84. // returns the associated object
  85. return $this->sexo;
  86. }
  87. /**
  88. * Method set_uf
  89. * Sample of usage: $var->uf = $object;
  90. * @param $object Instance of Cidade
  91. */
  92. public function set_uf(Cidade $object)
  93. {
  94. $this->uf = $object;
  95. $this->uf_id = $object->id;
  96. }
  97. /**
  98. * Method get_uf
  99. * Sample of usage: $var->uf->attribute;
  100. * @returns Cidade instance
  101. */
  102. public function get_uf()
  103. {
  104. // loads the associated object
  105. if (empty($this->uf))
  106. $this->uf = new Cidade($this->uf_id);
  107. // returns the associated object
  108. return $this->uf;
  109. }
  110. /**
  111. * Method set_cidade
  112. * Sample of usage: $var->cidade = $object;
  113. * @param $object Instance of Cidade
  114. */
  115. public function set_cidade(Cidade $object)
  116. {
  117. $this->cidade = $object;
  118. $this->cidade_id = $object->id;
  119. }
  120. /**
  121. * Method get_cidade
  122. * Sample of usage: $var->cidade->attribute;
  123. * @returns Cidade instance
  124. */
  125. public function get_cidade()
  126. {
  127. // loads the associated object
  128. if (empty($this->cidade))
  129. $this->cidade = new Cidade($this->cidade_id);
  130. // returns the associated object
  131. return $this->cidade;
  132. }
  133. /**
  134. * Method set_bairro
  135. * Sample of usage: $var->bairro = $object;
  136. * @param $object Instance of Cidade
  137. */
  138. public function set_bairro(Cidade $object)
  139. {
  140. $this->bairro = $object;
  141. $this->bairro_id = $object->id;
  142. }
  143. /**
  144. * Method get_uf
  145. * Sample of usage: $var->bairro->attribute;
  146. * @returns Cidade instance
  147. */
  148. public function get_bairro()
  149. {
  150. // loads the associated object
  151. if (empty($this->bairro))
  152. $this->bairro = new Cidade($this->bairro_id);
  153. // returns the associated object
  154. return $this->bairro;
  155. }
  156. }
  157. ?>


MODEL DA TABELA DEPENDENTE:
 
  1. <?php
  2. class Dependente extends TRecord
  3. {
  4. const TABLENAME = 'dependente';
  5. const PRIMARYKEY = 'dependente_id';
  6. const IDPOLICY = 'serial'; // {max, serial}
  7. /**
  8. * Constructor method
  9. */
  10. public function __construct($id = NULL, $callObjectLoad = TRUE)
  11. {
  12. parent::__construct($dependente_id, $callObjectLoad);
  13. parent::addAttribute('dependente_nome');
  14. parent::addAttribute('dependente_data_admissao');
  15. parent::addAttribute('dependente_data_carencia');
  16. parent::addAttribute('cliente_id');
  17. parent::addAttribute('status_dependente_id');
  18. }
  19. /**
  20. * Method set_cliente
  21. * Sample of usage: $var->cliente = $object;
  22. * @param $object Instance of Cidade
  23. */
  24. public function set_cliente(Cliente $object)
  25. {
  26. $this->cliente = $object;
  27. $this->cliente_id = $object->id;
  28. }
  29. /**
  30. * Method public function get_cliente()
  31. * Sample of usage: $var->cliente->attribute;
  32. * @returns Cidade instance
  33. */
  34. public function get_cliente()
  35. {
  36. // loads the associated object
  37. if (empty($this->cliente))
  38. $this->cliente = new Cliente($this->cliente_id);
  39. // returns the associated object
  40. return $this->cliente;
  41. }
  42. /**
  43. * Method set_status_dependente
  44. * Sample of usage: $var->status_dependente = $object;
  45. * @param $object Instance of Cidade
  46. */
  47. public function set_status_dependente(StatusDependente $object)
  48. {
  49. $this->status_dependente = $object;
  50. $this->status_dependente_id = $object->id;
  51. }
  52. /**
  53. * Method get_status_dependente
  54. * Sample of usage: $var->status_dependente->attribute;
  55. * @returns Cidade instance
  56. */
  57. public function get_status_dependente()
  58. {
  59. // loads the associated object
  60. if (empty($this->status_dependente))
  61. $this->status_dependente = new StatusDependente($this->status_dependente_id);
  62. // returns the associated object
  63. return $this->status_dependente;
  64. }
  65. }
  66. ?>


MODEL DA TABELA STATUS DEPENDENTE:
 
  1. <?php
  2. class StatusDependente extends TRecord
  3. {
  4. const TABLENAME = 'status_dependente';
  5. const PRIMARYKEY = 'id';
  6. const IDPOLICY = 'serial'; // {max, serial}
  7. /**
  8. * Constructor method
  9. */
  10. public function __construct($id = NULL, $callObjectLoad = TRUE)
  11. {
  12. parent::__construct($id, $callObjectLoad);
  13. parent::addAttribute('status_dependente');
  14. }
  15. }
  16. ?>

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (2)


NR

Tem algumas diferenças entre o nome dos campos e os identificadores de sessão. Ex:
 
  1. <?php
  2. $dependente_nome = new TEntry('dependente_nome');
  3. //onEdit
  4. $this->loadItems('Dependente', 'cliente_id', $object, 'item_dependente'); // item_dependente é o identificador da sessão, então vai gravar os dados no array da sessão como "item_dependente_dependente_nome"
  5. ?>

Sugiro criar esse mestre x detalhe pelo Studio e comparar com o atual para encontrar as diferenças
ET

OK, deu certo Nataniel. Obrigado.