Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Exibir Nome em vez de ID, no formulário de consulta Mestre Detal Não sei o que está a se passar, não consigo exibir nome das tabelas relacionadas usando esta técnica: Exemplo Tomador->nome. Usando este método na tela aparece sem informação, conforme mostra a imagem... Help Me Segue o codigo ...
AE
Exibir Nome em vez de ID, no formulário de consulta Mestre Detal  
Não sei o que está a se passar, não consigo exibir nome das tabelas relacionadas usando esta técnica: Exemplo Tomador->nome.
Usando este método na tela aparece sem informação, conforme mostra a imagem... Help Me

Segue o codigo

  1. <?php
  2.         $text_codigo  = new TTextDisplay($master_object->codigo'#333333''14px''');
  3.         $text_valor_premio  = new TTextDisplay(number_format($master_object->valor_premio,'2',',','.'), '#333333''14px''');
  4.         //$text_forma_pagamento  = new TTextDisplay($master_object->forma_pagamento, '#333333', '14px', '');
  5.         $text_data_inicio  = new TTextDisplay($master_object->data_inicio'red''14px''');
  6.         $text_data_fim  = new TTextDisplay($master_object->data_fim'red''14px''');
  7.         $text_tempo  = new TTextDisplay($master_object->tempo'#333333''14px''');
  8.         $text_tipo_apolice  = new TTextDisplay($master_object->tipo_apolice'#333333''14px''');
  9.         $text_codigo_plano  = new TTextDisplay($master_object->codigo_plano'#333333''14px''');
  10.         $text_codigo_tomador  = new TTextDisplay($master_object->Tomador->nome'#333333''14px'''); // EXEMPLO
  11.         $text_codigo_funcionario  = new TTextDisplay($master_object->codigo_funcionario'#333333''14px''');
  12. ?>

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (7)


MG

Bom dia.
Os models possuem os relacionamentos?
O campo Tomador é com "T" maiúsculo mesmo?
AE

Sim, os models possuem relacionamentos. O Tomador tanto com letra maiúscula e minúscula retorna valor null... Já tentei de várias formas não sei onde estou a falhar.
MG

Só mais uma pergunta, este código está no método __consruct()??
Teria como postar a classe para podermos tentar ajudar?
AE

Sim, em anexo o código.

CLASSE DE MODELO

  1. <?php
  2. /**
  3.  * Apolice Active Record
  4.  * @author  <your-name-here>
  5.  */
  6. class Apolice extends TRecord
  7. {
  8.     const TABLENAME 'apolice';
  9.     const PRIMARYKEY'codigo';
  10.     const IDPOLICY =  'max'// {max, serial}
  11.     
  12.     
  13.     private $tomador;
  14.     private $funcionario;
  15.     private $plano_seguro;
  16.     /**
  17.      * Constructor method
  18.      */
  19.     public function __construct($id NULL$callObjectLoad TRUE)
  20.     {
  21.         parent::__construct($id$callObjectLoad);
  22.         parent::addAttribute('valor_premio');
  23.         //parent::addAttribute('forma_pagamento');
  24.         parent::addAttribute('data_inicio');
  25.         parent::addAttribute('data_fim');
  26.         parent::addAttribute('tempo');
  27.         parent::addAttribute('tipo_apolice');
  28.         parent::addAttribute('referencia');
  29.         parent::addAttribute('codigo_plano');
  30.         parent::addAttribute('codigo_tomador');
  31.         parent::addAttribute('codigo_funcionario');
  32.         parent::addAttribute('estado_apolice');
  33.         
  34.     }
  35.     
  36.     /**
  37.      * Method set_tomador
  38.      * Sample of usage: $apolice->tomador = $object;
  39.      * @param $object Instance of Tomador
  40.      */
  41.     public function set_tomador(Tomador $object)
  42.     {
  43.         $this->tomador $object;
  44.         $this->tomador_id $object->id;
  45.     }
  46.     
  47.     /**
  48.      * Method get_tomador
  49.      * Sample of usage: $apolice->tomador->attribute;
  50.      * @returns Tomador instance
  51.      */
  52.     public function get_tomador()
  53.     {
  54.         // loads the associated object
  55.         if (empty($this->tomador))
  56.             $this->tomador = new Tomador($this->tomador_id);
  57.     
  58.         // returns the associated object
  59.         return $this->tomador;
  60.     }
  61.     
  62.     
  63.     /**
  64.      * Method set_funcionario
  65.      * Sample of usage: $apolice->funcionario = $object;
  66.      * @param $object Instance of Funcionario
  67.      */
  68.     public function set_funcionario(Funcionario $object)
  69.     {
  70.         $this->funcionario $object;
  71.         $this->funcionario_id $object->id;
  72.     }
  73.     
  74.     /**
  75.      * Method get_funcionario
  76.      * Sample of usage: $apolice->funcionario->attribute;
  77.      * @returns Funcionario instance
  78.      */
  79.     public function get_funcionario()
  80.     {
  81.         // loads the associated object
  82.         if (empty($this->funcionario))
  83.             $this->funcionario = new Funcionario($this->funcionario_id);
  84.     
  85.         // returns the associated object
  86.         return $this->funcionario;
  87.     }
  88.     
  89.     
  90.     /**
  91.      * Method set_plano_seguro
  92.      * Sample of usage: $apolice->plano_seguro = $object;
  93.      * @param $object Instance of PlanoSeguro
  94.      */
  95.     public function set_plano_seguro(PlanoSeguro $object)
  96.     {
  97.         $this->plano_seguro $object;
  98.         $this->plano_seguro_id $object->id;
  99.     }
  100.     
  101.     /**
  102.      * Method get_plano_seguro
  103.      * Sample of usage: $apolice->plano_seguro->attribute;
  104.      * @returns PlanoSeguro instance
  105.      */
  106.     public function get_plano_seguro()
  107.     {
  108.         // loads the associated object
  109.         if (empty($this->plano_seguro))
  110.             $this->plano_seguro = new PlanoSeguro($this->plano_seguro_id);
  111.     
  112.         // returns the associated object
  113.         return $this->plano_seguro;
  114.     }
  115.     
  116.     //METODO USER
  117.     public function set_system_user(SystemUser $object)
  118.     {
  119.         $this->system_user $object;
  120.         $this->system_user_id $object->id;
  121.     }
  122.     
  123.     public function get_system_user()
  124.     {
  125.         // loads the associated object
  126.         if (empty($this->system_user))
  127.             $this->system_user = new SystemUser($this->system_user_id);
  128.     
  129.         // returns the associated object
  130.         return $this->system_user;
  131.     }
  132.     
  133. }
  134.  ?>
AE


FORMULÁRIO DA VIEW

  1. <?php
  2. /**
  3.  * ApoliceFormView Master/Detail
  4.  * @author  <your name here>
  5.  */
  6. class ApoliceFormView extends TPage
  7. {
  8.     protected $form// form
  9.     protected $detail_list;
  10.     
  11.     /**
  12.      * Page constructor
  13.      */
  14.     public function __construct($param)
  15.     {
  16.         parent::__construct();
  17.         
  18.         parent::setTargetContainer('adianti_right_panel');
  19.         TTransaction::open('sgs');
  20.         $this->form = new BootstrapFormBuilder('form_Apolice');
  21.         $this->form->setFormTitle('APÓLICE');
  22.         
  23.         $master_object = new Apolice($param['key']);
  24.            
  25.         //$master_object['codigo_plano'] = PlanoSeguro::find(object->codigo_plano)->designacao;
  26.         
  27.         $label_codigo = new TLabel('Código:''#333333''14px''');
  28.         $label_valor_premio = new TLabel('Prémio:''#333333''14px''');
  29.         $label_forma_pagamento = new TLabel('Forma de Pagto:''#333333''14px''');
  30.         $label_data_inicio = new TLabel('Início:''#333333''14px''');
  31.         $label_data_fim = new TLabel('Fim:''#333333''14px''');
  32.         $label_tempo = new TLabel('Tempo:''#333333''14px''');
  33.         $label_tipo_apolice = new TLabel('Tipo:''#333333''14px''');
  34.         $label_codigo_plano = new TLabel('Plano:''#333333''14px''');
  35.         $label_codigo_tomador = new TLabel('Tomador:''#333333''14px''');
  36.         $label_codigo_funcionario = new TLabel('Operador:''#333333''14px''');
  37.         $text_codigo  = new TTextDisplay($master_object->codigo'#333333''14px''');
  38.         $text_valor_premio  = new TTextDisplay(number_format($master_object->valor_premio,'2',',','.'), '#333333''14px''');
  39.         //$text_forma_pagamento  = new TTextDisplay($master_object->forma_pagamento, '#333333', '14px', '');
  40.         $text_data_inicio  = new TTextDisplay($master_object->data_inicio'red''14px''');
  41.         $text_data_fim  = new TTextDisplay($master_object->data_fim'red''14px''');
  42.         $text_tempo  = new TTextDisplay($master_object->tempo'#333333''14px''');
  43.         $text_tipo_apolice  = new TTextDisplay($master_object->tipo_apolice'#333333''14px''');
  44.         $text_codigo_plano  = new TTextDisplay($master_object->codigo_plano'#333333''14px''');
  45.         $text_codigo_tomador  = new TTextDisplay($master_object->tomador->nome'#333333''14px''');
  46.         $text_codigo_funcionario  = new TTextDisplay($master_object->codigo_funcionario'#333333''14px''');
  47.         $row1 $this->form->addFields([$label_codigo],[$text_codigo],[$label_valor_premio],[$text_valor_premio]);
  48.         //$this->form->addFields([$label_forma_pagamento],[$text_forma_pagamento]);
  49.         $row2 $this->form->addFields([$label_data_inicio],[$text_data_inicio],[$label_data_fim],[$text_data_fim]);
  50.         $row3 $this->form->addFields([$label_tempo],[$text_tempo],[$label_tipo_apolice],[$text_tipo_apolice]);
  51.         $row4 $this->form->addFields([$label_codigo_plano],[$text_codigo_plano],[$label_codigo_tomador],[$text_codigo_tomador]);
  52.         $this->form->addFields([$label_codigo_funcionario],[$text_codigo_funcionario]);
  53.         
  54.         $this->detail_list = new TQuickGrid;
  55.         $this->detail_list->style 'width:100%';
  56.         $this->detail_list->disableDefaultClick();
  57.         
  58.         $segurado $this->detail_list->addQuickColumn('Beneficiário''codigo_segurado''left');
  59.         
  60.         $segurado->setTransformer(function($value){
  61.             return Segurado::findInTransaction('sgs',$value)->nome;
  62.         });   
  63.        
  64.         $this->detail_list->createModel();
  65.         
  66.         $items ApoliceSegurado::where('codigo_apolice''='$master_object->codigo)->load();
  67.         $this->detail_list->addItems($items);
  68.         
  69.         $icon = new TImage('fa:cubes #000000');
  70.         $title = new TTextDisplay("{$icon} Itens da Apólice"'#333333''15px''');
  71.         
  72.         $panel = new TPanelGroup($title'#f5f5f5');
  73.         $panel->class 'panel panel-default formView-detail';
  74.         $panel->add(new BootstrapDatagridWrapper($this->detail_list));
  75.         
  76.         $this->form->addContent([$panel]);
  77.         
  78.         //$btnLabel = new TLabel('Editar')
  79.         
  80.        
  81.         $this->form->addHeaderAction('Editar', new TAction(['ApoliceForm''onEdit'],['key'=>$master_object->codigo]), 'fa:pencil-square-o blue');
  82.         $this->form->addHeaderAction('Nova', new TAction(['ApoliceForm''onShow']), 'fa:plus blue');
  83.         $this->form->addHeaderActionLink_t('Close'), new TAction([$this'onClose']), 'fa:times red');
  84.        
  85.         // vertical box container
  86.         $container = new TVBox;
  87.         $container->style 'width: 100%'
  88.         // $container->add(new TXMLBreadCrumb('menu.xml', 'ApoliceList'));
  89.         $container->add($this->form);
  90.         TTransaction::close();
  91.         parent::add($container);
  92.     }
  93.     
  94.     public function onLoad($param)
  95.     {
  96.     
  97.     }
  98.     
  99.    public static function onClose($param)
  100.     {
  101.         TScript::create("Template.closeRightPanel()");
  102.     }
  103.     
  104.     
  105. }
  106. ?>
</your>
MG

Veja, no seu relacionamento você faz a ligação com o atributo $this->tomador_id,
porém o atributo listado é código_tomador
Tente substituir

De :
$this->tomador = new Tomador($this->tomador_id);


Por:
$this->tomador = new Tomador($this->codigo_tomador);



AE

Okay funcionou, muito obrigado Marcelo Gomes... Continua assim.