You can use the function SUM() SQL and cakephp’s ORM gives you easy access to it. In your case, within the controller, you can do the following:
use Cake\ORM\TableRegistry;
//Sua classe de tabela, diagamos que você tenha criado a classe de tabela: ProdutoEstoque.php
$produto = TableRegistry::get('EntradaEstoques');
$query = $produto->find();
$quantidade_sabao = $query->select(['sum' => $query->func()->sum('sabao')]);
$quantidade_pano = $query->select(['sum' => $query->func()->sum('pano')]);
//Envia os valores para a view
$this->set([
'quantidade_sabao' => $quantidade_sabao,
'quantidade_pano' => $quantidade_pano,
]);
Within the view (Your HTML) you will have access to the value of each variable:
<p>Quandidade de Sabão: <?= $quantidade_sabao ?></p>
Where is the code?.
– Wallace Maxters
Cakephp3 as is made
SQL
? has some code– novic
I don’t know how to do this code in the cakephp controller.
– TGO
Are you a beginner in Cakephp? @Thiagophilipp
– novic
in version 3.x yes, used the old 2.x.
– TGO
http://book.cakephp.org/3.0/pt/retrieving-data-and-resultsets.html will help, given the experience of v2?
– novic
@Virgilionovic was checking this tutorial but not how to use in my specific case.
– TGO
http://stackoverflow.com/a/32589142/6797930 has that link look at only!
– novic
you have any Entity ready that references this table?
– novic
Product Entity Stock created by Bake.
– TGO