Ao atualizar da erro não funciona o código da erro que Cannot convert value of type string to integer acho que o id não está indo numérico já fiz inúmeras tentativas sem acerto, da erro no atualizar. Estou utilizando Welcome to CakePHP 4.0.4 Strawberry
<?php
echo $this->Form->create($produto,['action'=>'salva']);
echo $this->Form->hidden('id');
echo $this->Form->input('nome');
echo "preco: ".$this->Form->input('preco');
echo $this->Form->input('descricao');
echo $this->Form->button('Salvar');
echo $this->Form->end();
?>
<?php
namespace App\Controller;
use Cake\ORM\TableRegistry;
class ProdutosController extends AppController {
public function index(){
$produtosTable = TableRegistry::get('Produtos');
$produtos = $produtosTable->find('all');
$this->set('produtos',$produtos);
}
public function novo(){
$produtosTable = TableRegistry::get('Produtos');
$produto = $produtosTable->newEmptyEntity();
$this->set('produto',$produto);
}
public function editar($id){
$produtosTable = TableRegistry::get('Produtos');
$produto = $produtosTable->get($id);
$this->set('produto', $produto);
$this->render('novo');
}
public function salva() {
$produtosTable = TableRegistry::get('Produtos');
$produto = $produtosTable->newEntity($this->request->getData());
if($produtosTable->save($produto)) {
$msg = "Produto salvo com sucesso";
} else {
$msg = "Erro ao salvar o produto";
}
$this->set('msg',$msg);
}
}
?>
Ao clicar em atualizar apresenta esse erro.
Cannot convert value of type string to integer InvalidArgumentException
C:\php-instalador\php\estoque\vendor\cakephp\cakephp\src\Database\Type\IntegerType.php Toggle Arguments
*/
protected function checkNumeric($value): void
{
if (!is_numeric($value)) {
throw new InvalidArgumentException(sprintf(
'Cannot convert value of type `%s` to integer',
getTypeName($value)
));
}
If you want to customize this error message, create templates\Error\error500.php