Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Erro Warning: number_format() expects parameter 1 to be float, s Boa tarde, Alguem sabe me dizer onde estou errando? Eu adptei o código de um exemplo do tutor mas não funcionou, segue código e tela. ...
RF
Erro Warning: number_format() expects parameter 1 to be float, s  
Boa tarde,

Alguem sabe me dizer onde estou errando?
Eu adptei o código de um exemplo do tutor mas não funcionou, segue código e tela.

  1. <?php
  2. /**
  3.  * ListaCadatroProdutos Form List
  4.  * @author  <your name here>
  5.  */
  6. class ListaCadatroProdutos extends TPage
  7. {
  8.     protected $form// form
  9.     protected $datagrid// datagrid
  10.     protected $pageNavigation;
  11.     protected $loaded;
  12.     
  13.     /**
  14.      * Form constructor
  15.      * @param $param Request
  16.      */
  17.     public function __construct$param )
  18.     {
  19.         parent::__construct();
  20.         
  21.         // creates the form
  22.         $this->form = new TQuickForm('form_Produto');
  23.         $this->form->class 'tform'// change CSS class
  24.         
  25.         $this->form->style 'display: table;width:100%'// change style
  26.         $this->form->setFormTitle('Produto');
  27.         
  28.         // create the form fields
  29.         $id              = new TEntry('id');
  30.         $tipo            = new TCombo('tipo');
  31.         $bairro          = new TEntry('bairro');
  32.         $unidis          = new TEntry('unidis');
  33.         $vlmaior         = new TEntry('vlmaior');
  34.         $vlmenor         = new TEntry('vlmenor');
  35.         $empreendimento  = new TEntry('empreendimento');
  36.         // definição dos formatos dos campos
  37.         $vlmaior        -> setNumericMask(2,',''.'true);
  38.         $vlmenor        -> setNumericMask(2,',''.'true);
  39.         $empreendimento ->style "text-transform: uppercase";
  40.         $bairro         ->style "text-transform: uppercase";
  41.         $unidis         ->style "text-transform: uppercase"
  42.         $id             ->setEditable(FALSE);
  43.         //Itens do estagio
  44.         $itemEstagio= array();
  45.         $itemEstagio['LANÇAMENTO']            = 'LANÇAMENTO'
  46.         $itemEstagio['EM OBRAS']              = 'EM OBRAS';
  47.         $itemEstagio['PRONTO PARA MORAR']     = 'PRONTO PARA MORAR';
  48.         $tipo->setValue('PRONTO PARA MORAR');
  49.         $tipo->addItems($itemEstagio);
  50.         // add the fields
  51.         $this->form->addQuickField('Código'$id,  200 );
  52.         $this->form->addQuickField('Tipo'$tipo,  200 );
  53.         $this->form->addQuickField('Bairro'$bairro,  200 );
  54.         $this->form->addQuickField('Unidade disponível'$unidis,  450 );
  55.         $this->form->addQuickField('Maior valor'$vlmaior,  200 );
  56.         $this->form->addQuickField('Menor valor'$vlmenor,  200 );
  57.         $this->form->addQuickField('Produto'$empreendimento,  200 );
  58.         /** samples
  59.          $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  60.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  61.          $fieldX->setSize( 100, 40 ); // set size
  62.          **/
  63.          
  64.         // create the form actions
  65.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'fa:floppy-o');
  66.         $this->form->addQuickAction(_t('New'),  new TAction(array($this'onClear')), 'bs:plus-sign green');
  67.         
  68.         // creates a Datagrid
  69.         $this->datagrid = new TDataGrid;
  70.         ##LIST_DECORATOR##
  71.         $this->datagrid->style 'width: 100%';
  72.         $this->datagrid->setHeight(320);
  73.         // $this->datagrid->datatable = 'true';
  74.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  75.  
  76.         // creates the datagrid columns
  77.         $column_id             = new TDataGridColumn('id''Código''left');
  78.         $column_tipo           = new TDataGridColumn('tipo''Tipo''left');
  79.         $column_bairro         = new TDataGridColumn('bairro''Bairro''left');
  80.         $column_unidis         = new TDataGridColumn('unidis''Unidade disponível''left');
  81.         $column_vlmaior        = new TDataGridColumn('vlmaior''Maior valor''left');
  82.         $column_vlmenor        = new TDataGridColumn('vlmenor''Menor valor''left');
  83.         $column_empreendimento = new TDataGridColumn('empreendimento''Produto''left');
  84.      
  85.         $column_vlmaior->setTransformer(array($this'formatValor'));
  86.         $column_vlmenor->setTransformer(array($this'formatValor'));
  87.      
  88.      
  89.         // add the columns to the DataGrid
  90.         $this->datagrid->addColumn($column_id);
  91.         $this->datagrid->addColumn($column_tipo);
  92.         $this->datagrid->addColumn($column_bairro);
  93.         $this->datagrid->addColumn($column_unidis);
  94.         $this->datagrid->addColumn($column_vlmaior);
  95.         $this->datagrid->addColumn($column_vlmenor);
  96.         $this->datagrid->addColumn($column_empreendimento);
  97.         
  98.         // creates two datagrid actions
  99.         $action1 = new TDataGridAction(array($this'onEdit'));
  100.         $action1->setUseButton(TRUE);
  101.         $action1->setButtonClass('btn btn-default');
  102.         //$action1->setLabel(_t('Edit'));
  103.         $action1->setImage('fa:pencil-square-o blue fa-lg');
  104.         $action1->setField('id');
  105.         
  106.         /*
  107.         $action2 = new TDataGridAction(array($this, 'onDelete'));
  108.         $action2->setUseButton(TRUE);
  109.         $action2->setButtonClass('btn btn-default');
  110.         $action2->setLabel(_t('Delete'));
  111.         $action2->setImage('fa:trash-o red fa-lg');
  112.         $action2->setField('id');
  113.         */
  114.         // add the actions to the datagrid
  115.         $this->datagrid->addAction($action1);
  116.        // $this->datagrid->addAction($action2);
  117.         
  118.         // create the datagrid model
  119.         $this->datagrid->createModel();
  120.         
  121.         // creates the page navigation
  122.         $this->pageNavigation = new TPageNavigation;
  123.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  124.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  125.         
  126.         /* vertical box container
  127.         $container = new TVBox;
  128.         $container->style = 'width: 90%';
  129.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  130.         $container->add($this->form);
  131.         $container->add($this->datagrid);
  132.         $container->add($this->pageNavigation);
  133.         
  134.         parent::add($container);
  135.         */
  136.         
  137.         
  138.         // Sub Menu Bonito
  139.         $container = new TVBox;
  140.         $container->style 'width: 90%';
  141.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  142.         $container->add($this->form);
  143.         $container->add(TPanelGroup::pack(''$this->datagrid));
  144.         $container->add($this->pageNavigation);
  145.         
  146.         parent::add($container);
  147.     }
  148.     
  149.     /**
  150.     Classes ---------------------------------------------------
  151.     */
  152.     public function formatValor($param)
  153.     {
  154.         $param number_format($param2',''.');
  155.         return $param;
  156.     }
  157.     
  158.     /**
  159.      * Load the datagrid with data
  160.      */
  161.     public function onReload($param NULL)
  162.     {
  163.         try
  164.         {
  165.             // open a transaction with database 'sample'
  166.             TTransaction::open('sample');
  167.             
  168.             // creates a repository for Produto
  169.             $repository = new TRepository('Produto');
  170.             $limit 10;
  171.             // creates a criteria
  172.             $criteria = new TCriteria;
  173.             
  174.             // default order
  175.             if (empty($param['order']))
  176.             {
  177.                 $param['order'] = 'id';
  178.                 $param['direction'] = 'asc';
  179.             }
  180.             $criteria->setProperties($param); // order, offset
  181.             $criteria->setProperty('limit'$limit);
  182.             
  183.             if (TSession::getValue('Produto_filter'))
  184.             {
  185.                 // add the filter stored in the session to the criteria
  186.                 $criteria->add(TSession::getValue('Produto_filter'));
  187.             }
  188.             
  189.             // load the objects according to criteria
  190.             $objects $repository->load($criteriaFALSE);
  191.             
  192.             $this->datagrid->clear();
  193.             if ($objects)
  194.             {
  195.                 // iterate the collection of active records
  196.                 foreach ($objects as $object)
  197.                 {
  198.                     // add the object inside the datagrid
  199.                     $this->datagrid->addItem($object);
  200.                 }
  201.             }
  202.             
  203.             // reset the criteria for record count
  204.             $criteria->resetProperties();
  205.             $count$repository->count($criteria);
  206.             
  207.             $this->pageNavigation->setCount($count); // count of records
  208.             $this->pageNavigation->setProperties($param); // order, page
  209.             $this->pageNavigation->setLimit($limit); // limit
  210.             
  211.             // close the transaction
  212.             TTransaction::close();
  213.             $this->loaded true;
  214.         }
  215.         catch (Exception $e// in case of exception
  216.         {
  217.             // shows the exception error message
  218.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  219.             
  220.             // undo all pending operations
  221.             TTransaction::rollback();
  222.         }
  223.     }
  224.     
  225.     /**
  226.      * Ask before deletion
  227.      */
  228.     public function onDelete($param)
  229.     {
  230.         // define the delete action
  231.         $action = new TAction(array($this'Delete'));
  232.         $action->setParameters($param); // pass the key parameter ahead
  233.         
  234.         // shows a dialog to the user
  235.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  236.     }
  237.     
  238.     /**
  239.      * Delete a record
  240.      */
  241.     public function Delete($param)
  242.     {
  243.         try
  244.         {
  245.             $key=$param['key']; // get the parameter $key
  246.             TTransaction::open('sample'); // open a transaction with database
  247.             $object = new Produto($keyFALSE); // instantiates the Active Record
  248.             $object->delete(); // deletes the object from the database
  249.             TTransaction::close(); // close the transaction
  250.             $this->onReload$param ); // reload the listing
  251.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted')); // success message
  252.         }
  253.         catch (Exception $e// in case of exception
  254.         {
  255.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  256.             TTransaction::rollback(); // undo all pending operations
  257.         }
  258.     }
  259.     
  260.     /**
  261.      * Save form data
  262.      * @param $param Request
  263.      */
  264.     public function onSave$param )
  265.     {
  266.         try
  267.         {
  268.             TTransaction::open('sample'); // open a transaction
  269.             
  270.             /**
  271.             // Enable Debug logger for SQL operations inside the transaction
  272.             TTransaction::setLogger(new TLoggerSTD); // standard output
  273.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  274.             **/
  275.             
  276.             $this->form->validate(); // validate form data
  277.             
  278.             $object = new Produto;  // create an empty object
  279.             $data $this->form->getData(); // get form data as array
  280.             $data  ->bairro strtoupper($data->bairro);
  281.             $data  ->empreendimento strtoupper($data->empreendimento);
  282.             $data  ->unidis strtoupper($data->unidis);
  283.             $object->fromArray( (array) $data); // load the object with data
  284.             $object->store(); // save the object
  285.             
  286.             // get the generated id
  287.             $data->id $object->id;
  288.             
  289.             $this->form->setData($data); // fill form data
  290.             TTransaction::close(); // close the transaction
  291.             
  292.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved')); // success message
  293.             $this->onReload(); // reload the listing
  294.         }
  295.         catch (Exception $e// in case of exception
  296.         {
  297.             new TMessage('error'$e->getMessage()); // shows the exception error message
  298.             $this->form->setData$this->form->getData() ); // keep form data
  299.             TTransaction::rollback(); // undo all pending operations
  300.         }
  301.     }
  302.     
  303.     /**
  304.      * Clear form data
  305.      * @param $param Request
  306.      */
  307.     public function onClear$param )
  308.     {
  309.         $this->form->clear(TRUE);
  310.     }
  311.     
  312.     /**
  313.      * Load object to form data
  314.      * @param $param Request
  315.      */
  316.     public function onEdit$param )
  317.     {
  318.         try
  319.         {
  320.             if (isset($param['key']))
  321.             {
  322.                 $key $param['key'];  // get the parameter $key
  323.                 TTransaction::open('sample'); // open a transaction
  324.                 $object = new Produto($key); // instantiates the Active Record
  325.                 $this->form->setData($object); // fill the form
  326.                 TTransaction::close(); // close the transaction
  327.             }
  328.             else
  329.             {
  330.                 $this->form->clear(TRUE);
  331.             }
  332.         }
  333.         catch (Exception $e// in case of exception
  334.         {
  335.             new TMessage('error'$e->getMessage()); // shows the exception error message
  336.             TTransaction::rollback(); // undo all pending operations
  337.         }
  338.     }
  339.     
  340.     /**
  341.      * method show()
  342.      * Shows the page
  343.      */
  344.     public function show()
  345.     {
  346.         // check if the datagrid is already loaded
  347.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  348.         {
  349.             $this->onReloadfunc_get_arg(0) );
  350.         }
  351.         parent::show();
  352.     }
  353. }

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (4)


NR

Em alguma situação o php está interpretando a varíavel $param como string quando deveria ser float:

Algum dos valores dessas colunas está vindo vazio do banco?

Você está gravando os dados no banco com vírgula e ponto(413.400,00)?
RF

Boa tarde...

Na verdade eu só queria ver na DataGrid o valor dos campos Maior Valor e Menor Valor em formato númerico, se não for possível tudo bem eu vou sobreviver.
NR

Pra não aparecer o erro é só fazer o cast da variável para float:
  1. <?php
  2. $param number_format((float)$param2',''.');
  3. ?>
RF

Muito obrigado, era o que eu precisava. Tenho outras dúvidas mas depois eu posto, outro dia eu pergunto mais...