Lançado Adianti Framework 7.6!
Clique aqui para saber mais
2 frames para duas imagens no mesmo form Pessoal tenho um formulário com dois campos de imagem para isso criei 2 frames, conforme código abaixo. Porém ao exibir a imagem está indo para a imagem da resposta creio eu por ter sido a ultima imagem adicionada ao frame. Como faço para identificar em qual frame quero carregar minha imagem? ...
LB
2 frames para duas imagens no mesmo form  
Fechado
Pessoal tenho um formulário com dois campos de imagem para isso criei 2 frames, conforme código abaixo. Porém ao exibir a imagem está indo para a imagem da resposta creio eu por ter sido a ultima imagem adicionada ao frame. Como faço para identificar em qual frame quero carregar minha imagem?
  1. <?php e
  2. //adicionando imagem
  3.         $this->form->addQuickField('Imagem para Enunciado'$imagem,  400);
  4.         $this->frame = new TElement('div');
  5.         $this->frame->id 'photo_frame';
  6.         $this->frame->style 'width:400px;height:auto;min-height:200px;border:1px solid gray;padding:4px;';
  7.         $row $this->form->addRow();
  8.         $row->addCell('');
  9.         $row->addCell($this->frame);
  10.         //adiconando imagem resposta
  11.         $this->form->addQuickField('Imagem para Resposta'$imagem_resposta,  400);
  12.         $this->frame = new TElement('div');
  13.         $this->frame->id 'photo_frame_respota';
  14.         $this->frame->style 'width:400px;height:auto;min-height:200px;border:1px solid gray;padding:4px;';
  15.         $row $this->form->addRow();
  16.         $row->addCell('');
  17.         $row->addCell($this->frame);
  18. ?>



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 (9)


NR

Leandro, poste todo o código, não consegui simular o problema.
LB

Segue Nataniel o código do meu Form

  1. <?php e
  2. /**
  3.  * QuestoesFormList Registration
  4.  * @author  Leandro J N Barbosa
  5.  */
  6. class QuestoesFormList extends TPage
  7. {
  8.     protected $form// form
  9.     private   $frame;
  10.     protected $datagrid// datagrid
  11.     protected $pageNavigation;
  12.     protected $loaded;
  13.     
  14.     /**
  15.      * Class constructor
  16.      * Creates the page and the registration form
  17.      */
  18.     function __construct()
  19.     {
  20.         parent::__construct();
  21.         
  22.         // creates the form
  23.         $this->form = new TQuickForm('form_Questoes');
  24.         $this->form->class 'tform'// CSS class
  25.         $this->form->setFormTitle('Questões'); // define the form title
  26.         
  27.         // create the form fields
  28.         $cod_quest                      = new TEntry('cod_quest');
  29.         $cod_cont                       = new  ">TDBSeekButton('cod_cont','super_prova','form_Questoes','Conteudo','descricao','cod_cont','conteudo_descricao');
  30.         $conteudo_descricao             = new TEntry('conteudo_descricao');
  31.         $enunciado                      = new TText('enunciado');
  32.         $imagem                         = new TFile('imagem');
  33.         $alternativas                   = new TText('alternativas');
  34.         $resposta                       = new TText('resposta');
  35.         $imagem_resposta                = new TFile('imagem_resposta');
  36.         
  37.         // complete upload action
  38.         $imagem->setCompleteAction(new TAction(array($this'onComplete')));
  39.         
  40.         // complete upload action resposta
  41.         $imagem_resposta->setCompleteAction(new TAction(array($this'onCompleteResposta')));
  42.         // add the fields
  43.         $this->form->addQuickField('Cód. Questão'$cod_quest,  100);
  44.         $this->form->addQuickField('Cód. Conteúdo'$cod_cont,  100, new TRequiredValidator );
  45.         $this->form->addQuickField('Conteúdo/Tema'$conteudo_descricao,  400);
  46.         $this->form->addQuickField('Enunciado'$enunciado,  600, new TRequiredValidator );
  47.         $this->form->addQuickField('Alternativas'$alternativas,  600);
  48.         $this->form->addQuickField('Resposta'$resposta,  600, new TRequiredValidator );
  49.         //adicionando imagem
  50.         $this->form->addQuickField('Imagem para Enunciado'$imagem,  400);
  51.         $this->frame = new TElement('div');
  52.         $this->frame->id 'photo_frame';
  53.         $this->frame->style 'width:400px;height:auto;min-height:200px;border:1px solid gray;padding:4px;';
  54.         $row $this->form->addRow();
  55.         $row->addCell('');
  56.         $row->addCell($this->frame);
  57.         //adiconando imagem resposta
  58.         $this->form->addQuickField('Imagem para Resposta'$imagem_resposta,  400);
  59.         $this->frame = new TElement('div');
  60.         $this->frame->id 'photo_frame_respota';
  61.         $this->frame->style 'width:400px;height:auto;min-height:200px;border:1px solid gray;padding:4px;';
  62.         $row $this->form->addRow();
  63.         $row->addCell('');
  64.         $row->addCell($this->frame);
  65.         
  66.         //desbilitando campo
  67.         $cod_quest->setEditable(FALSE);
  68.         $conteudo_descricao->setEditable(FALSE);
  69.                 
  70.         //Definindo Tamnahos
  71.         $imagem->setSize(40040);
  72.         $imagem_resposta->setSize(40040);
  73.         $conteudo_descricao->setSize(40040);
  74.         $enunciado->setSize(600100);
  75.         $resposta->setSize(600100);
  76.         $alternativas->setSize(600100);
  77.         // create the form actions
  78.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'ico_save.png');
  79.         $this->form->addQuickAction(_t('New'),  new TAction(array($this'onEdit')), 'ico_new.png');
  80.         
  81.         // creates a DataGrid
  82.         $this->datagrid = new TQuickGrid;
  83.         $this->datagrid->setHeight(320);
  84.         
  85.         // creates the datagrid columns
  86.         $cod_quest $this->datagrid->addQuickColumn('Cód. Questão''cod_quest''left'80);
  87.         //$cod_cont = $this->datagrid->addQuickColumn('Cód. Conteúdo', 'cod_cont', 'left', 80);
  88.         $conteudo_descricao $this->datagrid->addQuickColumn('Conteúdo/Tema''conteudo_descricao''left'300);
  89.         $enunciado $this->datagrid->addQuickColumn('Enunciado''enunciado''left'450);
  90.         $alternativas $this->datagrid->addQuickColumn('Alternativas''alternativas''left'400);
  91.         $imagem $this->datagrid->addQuickColumn('Imagem''imagem''left'300);
  92.         $resposta $this->datagrid->addQuickColumn('Resposta''resposta''left'450);
  93.         $imagem_resposta $this->datagrid->addQuickColumn('Imagem Resposta''imagem_resposta''left'300);
  94.                
  95.         // create the datagrid actions
  96.         $edit_action   = new TDataGridAction(array($this'onEdit'));
  97.         $delete_action = new TDataGridAction(array($this'onDelete'));
  98.         
  99.         // add the actions to the datagrid
  100.         $this->datagrid->addQuickAction(_t('Edit'), $edit_action'cod_quest''ico_edit.png');
  101.         $this->datagrid->addQuickAction(_t('Delete'), $delete_action'cod_quest''ico_delete.png');
  102.         
  103.         // create the datagrid model
  104.         $this->datagrid->createModel();
  105.         
  106.         //Cria popover de imagem
  107.         $this->datagrid->enablePopover('Imagem'"<img src='{imagem}'>");
  108.         
  109.         // creates the page navigation
  110.         $this->pageNavigation = new TPageNavigation;
  111.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  112.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  113.         
  114.         // create the datagrid model
  115.         $this->datagrid->createModel();
  116.         
  117.         // creates the page navigation
  118.         $this->pageNavigation = new TPageNavigation;
  119.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  120.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  121.         
  122.         // create the page container
  123.         $container TVBox::pack$this->form$this->datagrid$this->pageNavigation);
  124.         parent::add($container);
  125.     }
  126.     /**
  127.      * method onReload()
  128.      * Load the datagrid with the database objects
  129.      */
  130.     function onReload($param NULL)
  131.     {
  132.         try
  133.         {
  134.             // open a transaction with database 'super_prova'
  135.             TTransaction::open('super_prova');
  136.             
  137.             // creates a repository for Questoes
  138.             $repository = new TRepository('Questoes');
  139.             $limit 10;
  140.             // creates a criteria
  141.             $criteria = new TCriteria;
  142.             
  143.             // default order
  144.             if (empty($param['order']))
  145.             {
  146.                 $param['order'] = 'cod_quest';
  147.                 $param['direction'] = 'asc';
  148.             }
  149.             $criteria->setProperties($param); // order, offset
  150.             $criteria->setProperty('limit'$limit);
  151.             
  152.             if (TSession::getValue('Questoes_filter'))
  153.             {
  154.                 // add the filter stored in the session to the criteria
  155.                 $criteria->add(TSession::getValue('Questoes_filter'));
  156.             }
  157.             
  158.             // load the objects according to criteria
  159.             $objects $repository->load($criteriaFALSE);
  160.             
  161.             $this->datagrid->clear();
  162.             if ($objects)
  163.             {
  164.                 // iterate the collection of active records
  165.                 foreach ($objects as $object)
  166.                 {
  167.                     // add the object inside the datagrid
  168.                     $this->datagrid->addItem($object);
  169.                 }
  170.             }
  171.                        
  172.             // reset the criteria for record count
  173.             $criteria->resetProperties();
  174.             $count$repository->count($criteria);
  175.        
  176.             $this->pageNavigation->setCount($count); // count of records
  177.             $this->pageNavigation->setProperties($param); // order, page
  178.             $this->pageNavigation->setLimit($limit); // limit
  179.             
  180.             // close the transaction
  181.             TTransaction::close();
  182.             $this->loaded true;
  183.         }
  184.         catch (Exception $e// in case of exception
  185.         {
  186.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  187.             TTransaction::rollback(); // undo all pending operations
  188.         }
  189.     }
  190.     
  191.     /**
  192.      * method onDelete()
  193.      * executed whenever the user clicks at the delete button
  194.      * Ask if the user really wants to delete the record
  195.      */
  196.     function onDelete($param)
  197.     {
  198.         // define the delete action
  199.         $action = new TAction(array($this'Delete'));
  200.         $action->setParameters($param); // pass the key parameter ahead
  201.         
  202.         // shows a dialog to the user
  203.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  204.     }
  205.     
  206.     /**
  207.      * method Delete()
  208.      * Delete a record
  209.      */
  210.     function Delete($param)
  211.     {
  212.         try
  213.         {
  214.             // get the parameter $key
  215.             $key=$param['key'];
  216.             
  217.             TTransaction::open('super_prova'); // open the transaction
  218.             $object = new Questoes($keyFALSE); // instantiates the Active Record
  219.             if ($object->imagem != '')
  220.                 unlink($object->imagem);
  221.             if ($object->imagem_resposta != '')    
  222.                 unlink($object->imagem_resposta);
  223.             $object->delete(); // deletes the object
  224.             TTransaction::close(); // close the transaction
  225.             
  226.             $this->onReload$param ); // reload the listing
  227.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted')); // success message
  228.         }
  229.         catch (Exception $e// in case of exception
  230.         {
  231.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  232.             TTransaction::rollback(); // undo all pending operations
  233.         }
  234.     }
  235.     
  236.     /**
  237.      * method onSave()
  238.      * Executed whenever the user clicks at the save button
  239.      */
  240.     function onSave()
  241.     {
  242.         try
  243.         {
  244.             TTransaction::open('super_prova'); // open a transaction with database
  245.             
  246.             // get the form data into an active record Questoes
  247.             $object $this->form->getData('Questoes');
  248.             $this->form->validate(); // form validation
  249.             //Gravando Imagem
  250.             $source_file       'tmp/'.$object->imagem;
  251.             $target_file       'images/' $object->imagem;
  252.             $extensao          pathinfo $object->imagemPATHINFO_EXTENSION ); 
  253.             $source_file_resp  'tmp/'.$object->imagem_resposta;
  254.             $target_file_resp  'images/' $object->imagem_resposta;
  255.             $extensao_resp     pathinfo $object->imagem_respostaPATHINFO_EXTENSION );           
  256.             if($extensao != '')  
  257.                 if ( ($extensao != 'jpg') AND ($extensao != 'jpeg') AND ($extensao != 'bmp') AND ($extensao != 'gif') AND ($extensao != 'png'))
  258.                 {
  259.                      unlink($source_file);
  260.                      throw new Exception(' <b>Arquivo inválido, o arquivo não é uma extensão de imagem, selecione outro arquivo de imagem!</b><br>
  261.                                            <b>Extensões permitidas (JPG, JPEG, BMP, GIF, PNG)</b>');
  262.                 }   
  263.             if($extensao_resp != '')  
  264.                 if ( ($extensao_resp != 'jpg') AND ($extensao_resp != 'jpeg') AND ($extensao_resp != 'bmp') AND ($extensao_resp != 'gif') AND ($extensao_resp != 'png'))
  265.                 {
  266.                      unlink($source_file_resp);
  267.                      throw new Exception(' <b>Arquivo inválido, o arquivo não é uma extensão de imagem, selecione outro arquivo de imagem!</b><br>
  268.                                            <b>Extensões permitidas (JPG, JPEG, BMP, GIF, PNG)</b>');
  269.                 }                   
  270.             // if the user uploaded a source file
  271.             //new TMessage($object->cod_quest);
  272.             if (file_exists($source_file) AND ($extensao != ''))
  273.             {
  274.                 //move to the target directory
  275.                 $novoNome      uniqid time () ) .'.'$extensao;
  276.                 $target_file   'images/'.$novoNome;
  277.                 rename($source_file$target_file);
  278.                 //atualizando a imagem 
  279.                 $object->imagem $target_file;                                                           
  280.                 $image = new TImage($object->imagem);
  281.                 $image->style 'width: 100%';
  282.                 $this->frame->add$image );
  283.             }
  284.             if (file_exists($source_file_resp) AND ($extensao_resp != ''))
  285.             {
  286.                 //move to the target directory
  287.                 $novoNome_resp      uniqid time () ) .'.'$extensao_resp;
  288.                 $target_file_resp   'images/'.$novoNome_resp;
  289.                 rename($source_file_resp$target_file_resp);
  290.                 //atualizando a imagem 
  291.                 $object->imagem_resposta $target_file_resp;                                                         
  292.                 $image_resp = new TImage($object->imagem_resposta);
  293.                 $image_resp->style 'width: 100%';
  294.                 $this->frame->add$image_resp );
  295.             }
  296.             //Fim Gravação imagem
  297.             $object->store(); // stores the object
  298.             $this->form->setData($object); // fill the form with the active record data
  299.             TTransaction::close(); // close the transaction
  300.             
  301.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved')); // success message
  302.             $this->onReload(); // reload the listing
  303.         }
  304.         catch (Exception $e// in case of exception
  305.         {
  306.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  307.             TTransaction::rollback(); // undo all pending operations
  308.         }
  309.     }
  310.     
  311.     /**
  312.      * method onEdit()
  313.      * Executed whenever the user clicks at the edit button da datagrid
  314.      */
  315.     function onEdit($param)
  316.     {
  317.         try
  318.         {
  319.             if (isset($param['key']))
  320.             {
  321.                 
  322.                 $key=$param['key']; // get the parameter $key
  323.                 TTransaction::open('super_prova'); // open a transaction with the database
  324.                 $object = new Questoes($key); // instantiates the Active Record
  325.                 //mostra imagem
  326.                 if ($object)
  327.                 {    
  328.                     $image = new TImage($object->imagem);
  329.                     $image->style 'width: 100%';
  330.                     $this->frame->id 'photo_frame';
  331.                     $this->frame->add$image );
  332.                     $image_resp = new TImage($object->imagem_resposta);
  333.                     $image_resp->style 'width: 100%';
  334.                     $this->frame->id 'photo_frame_resposta';
  335.                     $this->frame->add$image_resp );
  336.                     
  337.                 }                
  338.                 $this->form->setData($object); // fill the form with the active record data
  339.                 TTransaction::close(); // close the transaction
  340.             }
  341.             else
  342.             {
  343.                 $this->form->clear();
  344.             }                       
  345.             
  346.         }
  347.         catch (Exception $e// in case of exception
  348.         {
  349.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  350.             TTransaction::rollback(); // undo all pending operations
  351.         }
  352.     }
  353.     
  354.     /**
  355.      * method show()
  356.      * Shows the page e seu conteúdo
  357.      */
  358.     function show()
  359.     {
  360.         // check if the datagrid is already loaded
  361.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  362.         {
  363.             $this->onReloadfunc_get_arg(0) );
  364.         }
  365.         parent::show();
  366.     }
  367.     
  368.     /**
  369.      * On complete upload
  370.      */
  371.     public static function onComplete($param)
  372.     {
  373.         new TMessage('info''Upload completed: '.$param['imagem']);
  374.         
  375.         // refresh photo_frame
  376.         TScript::create("$('#photo frame').html('')");
  377.         TScript::create("$('#photo_frame').append(\\"<img style='width:100%' src='tmp/{$param['imagem']}'>\\");");
  378.     }
  379.     
  380.     /**
  381.      * On complete upload
  382.      */
  383.     public static function onCompleteResposta($param)
  384.     {
  385.         new TMessage('info''Upload completed: '.$param['imagem_resposta']);
  386.         
  387.         // refresh photo_frame_reposta
  388.         TScript::create("$('#photo frame_resposta').html('')");
  389.         TScript::create("$('#photo_frame_resposta').append(\\"<img style='width:100%' src='tmp/{$param['imagem_resposta']}'>\\");");
  390.     }
  391.     
  392. }
  393. ?>

NR

Leandro, verifique a linha 62, há um erro na escrita. Deveria ser RESPOSTA ao invés de RESPOTA. Tá faltando o S.
  1. <?php
  2. $this->frame->id 'photo_frame_respota';
  3. ?>

LB

Nataniel, apesar do erro de digitação nã é ele quem está causando o problema, a imagem está carregando no frame errado, tenho dois campos de imagem e a "Imagem Enunciado" está sendo carregada dento do frame destinado a "Imagem Resposta". Estou meio perdido com esse problema.
NR

Aqui funcionou certinho, cada imagem em seu frame.
LB

Nataniel tem como identificar a frame que quero que a imagem seja criada tipo quando dou o comando $this->frame->add( $image );
NR

Leandro, provavelmente teu problema está em utilizar a mesma variável para os 2 frames: $this->frame
Acontece que ao sair do construct, $this->frame só corresponde ao frame2 e você não tem mais a instância do frame1.

Criando 2 variáveis o problema deve ser resolvido
LB

Vou tentar e reporto o resultado.
Obrigado por enquanto.
LB

Nataniel, você é o mestre do pHP kkkkkk, funcionou perfeitamente com duas variáveis, muito obrigado!

Um abraço.