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. Persistence
  3. Presentation
  4. Organization
  5. Search
  6. Home Screen View Source-code
  7. Book
  8. h
  9. Organization
  10. Complex views
  11. Product list
  12. Product
  13. ID
  14. 1
  15. Description
  16. Pendrive 512Mb
  17. Stock
  18. 10,00
  19. Sale Price
  20. 40,00
  21. Unity
  22. Photo Path Escolher arquivo
  23. Save Clear List
  24. app/control/Organization/ComplexViews/ProductForm.class.php
  25. 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. function __construct()
  17. {
  18. parent::__construct();
  19. // creates the form
  20. $this->form = new TQuickForm('form_Product');
  21. $this->form->class = 'tform'; // CSS class
  22. // defines the form title
  23. $this->form->setFormTitle('Product');
  24. // define the database and the Active Record
  25. parent::setDatabase('samples');
  26. parent::setActiveRecord('Product');
  27. // units
  28. $units = array('PC' => 'Pieces', 'GR' => 'Grain');
  29. // create the form fields
  30. $id = new TEntry('id');
  31. $description = new TEntry('description');
  32. $stock = new TEntry('stock');
  33. $sale_price = new TEntry('sale_price');
  34. $unity = new TCombo('unity');
  35. $photo_path = new TFile('photo_path');
  36. // complete upload action
  37. $photo_path->setCompleteAction(new TAction(array($this, 'onComplete')));
  38. $id->setEditable( FALSE );
  39. $unity->addItems( $units );
  40. $stock->setNumericMask(2, ',', '.', TRUE); // TRUE: process mask when editing and saving
  41. $sale_price->setNumericMask(2, ',', '.', TRUE); // TRUE: process mask when editing and saving
  42. // add the form fields
  43. $this->form->addQuickField('ID', $id, '30%');
  44. $this->form->addQuickField('Description', $description, '70%', new TRequiredValidator);
  45. $this->form->addQuickField('Stock', $stock, '70%', new TRequiredValidator);
  46. $this->form->addQuickField('Sale Price', $sale_price, '70%', new TRequiredValidator);
  47. $this->form->addQuickField('Unity', $unity, '70%', new TRequiredValidator);
  48. $this->form->addQuickField('Photo Path', $photo_path, '70%');
  49. $this->frame = new TElement('div');
  50. $this->frame->id = 'photo_frame';
  51. $this->frame->style = 'width:400px;height:auto;min-height:200px;border:1px solid gray;padding:4px;';
  52. $row = $this->form->addRow();
  53. $row->addCell('');
  54. $row->addCell($this->frame);
  55. // add the actions
  56. $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:save green');
  57. $this->form->addQuickAction(_t('Clear'), new TAction(array($this, 'onEdit')), 'fa:eraser red');
  58. $this->form->addQuickAction(_t('List'), new TAction(array('ProductList', 'onReload')), 'fa:table blue');
  59. $vbox = new TVBox;
  60. $vbox->add(new TXMLBreadCrumb('menu.xml', 'ProductList'));
  61. $vbox->add($this->form);
  62. parent::add($vbox);
  63. }
  64. /**
  65. * On complete upload
  66. */
  67. public static function onComplete($param)
  68. {
  69. new TMessage('info', 'Upload completed: '.$param['photo_path']);
  70. // refresh photo_frame
  71. TScript::create("$('#photo_frame').html('')");
  72. TScript::create("$('#photo_frame').append(\"<img style='width:100%' src='tmp/{$param['photo_path']}'>\");");
  73. }
  74. /**
  75. * Edit product
  76. */
  77. public function onEdit($param)
  78. {
  79. $object = parent::onEdit($param);
  80. if ($object)
  81. {
  82. $image = new TImage($object->photo_path);
  83. $image->style = 'width: 100%';
  84. $this->frame->add( $image );
  85. }
  86. }
  87. /**
  88. * Overloaded method onSave()
  89. * Executed whenever the user clicks at the save button
  90. */
  91. public function onSave()
  92. {
  93. // first, use the default onSave()
  94. $object = parent::onSave();
  95. // if the object has been saved
  96. if ($object instanceof Product)
  97. {
  98. $source_file = 'tmp/'.$object->photo_path;
  99. $target_file = 'images/' . $object->photo_path;
  100. $finfo = new finfo(FILEINFO_MIME_TYPE);
  101. // if the user uploaded a source file
  102. if (file_exists($source_file) AND ($finfo->file($source_file) == 'image/png' OR $finfo->file($source_file) == 'image/jpeg'))
  103. {
  104. // move to the target directory
  105. rename($source_file, $target_file);
  106. try
  107. {
  108. TTransaction::open($this->database);
  109. // update the photo_path
  110. $object->photo_path = 'images/'.$object->photo_path;
  111. $object->store();
  112. TTransaction::close();
  113. }
  114. catch (Exception $e) // in case of exception
  115. {
  116. new TMessage('error', $e->getMessage());
  117. TTransaction::rollback();
  118. }
  119. }
  120. $image = new TImage($object->photo_path);
  121. $image->style = 'width: 100%';
  122. $this->frame->add( $image );
  123. }
  124. }
  125. }
  126. ?>


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?