Lançado Adianti Framework 8.1!
Clique aqui para saber mais
BootStrapWrapper com TFIle Boa tarde, alguem teria algum exemplo de TFile com upoad de imagem usando o bootstrap, seria o formulario do tutor ref. cadastro de produtos mas com bootstrap. ...
AB
BootStrapWrapper com TFIle  
Boa tarde, alguem teria algum exemplo de TFile com upoad de imagem usando o bootstrap, seria o formulario do tutor ref. cadastro de produtos mas com bootstrap.
  1. <?php
  2.  
  3.   
  4. Persistence 
  5. Presentation 
  6. Organization 
  7. Search
  8.  Home Screen  View Source-code
  9. Book
  10. h
  11. Organization
  12. Complex views
  13. Product list
  14. Product
  15. ID    
  16. 1
  17. Description    
  18. Pendrive 512Mb
  19. Stock    
  20. 10,00
  21. Sale Price    
  22. 40,00
  23. Unity    
  24. Photo Path     Escolher arquivo
  25.  
  26.  Save    Clear    List
  27. app/control/Organization/ComplexViews/ProductForm.class.php
  28. Close
  1. <?php
  2. /**
  3.  * Product Form
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class ProductForm extends TStandardForm
  13. {
  14.     protected $form;
  15.     private   $frame;
  16.     
  17.     function __construct()
  18.     {
  19.         parent::__construct();
  20.         
  21.         // creates the form
  22.         $this->form = new TQuickForm('form_Product');
  23.         $this->form->class 'tform'// CSS class
  24.         
  25.         // defines the form title
  26.         $this->form->setFormTitle('Product');
  27.         
  28.         // define the database and the Active Record
  29.         parent::setDatabase('samples');
  30.         parent::setActiveRecord('Product');
  31.         
  32.         // units
  33.         $units = array('PC' => 'Pieces''GR' => 'Grain');
  34.         
  35.         // create the form fields
  36.         $id                             = new TEntry('id');
  37.         $description                    = new TEntry('description');
  38.         $stock                          = new TEntry('stock');
  39.         $sale_price                     = new TEntry('sale_price');
  40.         $unity                          = new TCombo('unity');
  41.         $photo_path                     = new TFile('photo_path');
  42.         
  43.         // complete upload action
  44.         $photo_path->setCompleteAction(new TAction(array($this'onComplete')));
  45.         
  46.         $id->setEditableFALSE );
  47.         $unity->addItems$units );
  48.         $stock->setNumericMask(2',''.'TRUE); // TRUE: process mask when editing and saving
  49.         $sale_price->setNumericMask(2',''.'TRUE); // TRUE: process mask when editing and saving
  50.         
  51.         // add the form fields
  52.         $this->form->addQuickField('ID'$id,  '30%');
  53.         $this->form->addQuickField('Description'$description,  '70%', new TRequiredValidator);
  54.         $this->form->addQuickField('Stock'$stock,  '70%', new TRequiredValidator);
  55.         $this->form->addQuickField('Sale Price'$sale_price,  '70%', new TRequiredValidator);
  56.         $this->form->addQuickField('Unity'$unity,  '70%', new TRequiredValidator);
  57.         $this->form->addQuickField('Photo Path'$photo_path,  '70%');
  58.         
  59.         $this->frame = new TElement('div');
  60.         $this->frame->id 'photo_frame';
  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.         // add the actions
  67.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'fa:save green');
  68.         $this->form->addQuickAction(_t('Clear'), new TAction(array($this'onEdit')), 'fa:eraser red');
  69.         $this->form->addQuickAction(_t('List'), new TAction(array('ProductList''onReload')), 'fa:table blue');
  70.         $vbox = new TVBox;
  71.         $vbox->add(new TXMLBreadCrumb('menu.xml''ProductList'));
  72.         $vbox->add($this->form);
  73.         parent::add($vbox);
  74.     }
  75.     
  76.     /**
  77.      * On complete upload
  78.      */
  79.     public static function onComplete($param)
  80.     {
  81.         new TMessage('info''Upload completed: '.$param['photo_path']);
  82.         
  83.         // refresh photo_frame
  84.         TScript::create("$('#photo_frame').html('')");
  85.         TScript::create("$('#photo_frame').append(\"<img style='width:100%' src='tmp/{$param['photo_path']}'>\");");
  86.     }
  87.     
  88.     /**
  89.      * Edit product
  90.      */
  91.     public function onEdit($param)
  92.     {
  93.         $object parent::onEdit($param);
  94.         if ($object)
  95.         {
  96.             $image = new TImage($object->photo_path);
  97.             $image->style 'width: 100%';
  98.             $this->frame->add$image );
  99.         }
  100.     }
  101.     
  102.     /**
  103.      * Overloaded method onSave()
  104.      * Executed whenever the user clicks at the save button
  105.      */
  106.     public function onSave()
  107.     {
  108.         // first, use the default onSave()
  109.         $object parent::onSave();
  110.         
  111.         // if the object has been saved
  112.         if ($object instanceof Product)
  113.         {
  114.             $source_file   'tmp/'.$object->photo_path;
  115.             $target_file   'images/' $object->photo_path;
  116.             $finfo         = new finfo(FILEINFO_MIME_TYPE);
  117.             
  118.             // if the user uploaded a source file
  119.             if (file_exists($source_file) AND ($finfo->file($source_file) == 'image/png' OR $finfo->file($source_file) == 'image/jpeg'))
  120.             {
  121.                 // move to the target directory
  122.                 rename($source_file$target_file);
  123.                 try
  124.                 {
  125.                     TTransaction::open($this->database);
  126.                     // update the photo_path
  127.                     $object->photo_path 'images/'.$object->photo_path;
  128.                     $object->store();
  129.                     
  130.                     TTransaction::close();
  131.                 }
  132.                 catch (Exception $e// in case of exception
  133.                 {
  134.                     new TMessage('error'$e->getMessage());
  135.                     TTransaction::rollback();
  136.                 }
  137.             }
  138.             $image = new TImage($object->photo_path);
  139.             $image->style 'width: 100%';
  140.             $this->frame->add$image );
  141.         }
  142.     }
  143. }
  144.  
  145. ?>


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


NR

Acho que a BootstrapFormWrapper é meio limitada nesse sentido. Pelo que vi não há como adicionar outros conteúdos sem algum tipo de alteração na classe. Usar a BootstrapFormBuilder não é uma opção?