Form via post and pass on beforeSave

0

I am not able to send the data via post, it is via put.

It is not going through the beforeSave callback and when I debug the request in the controller, it is put. Maybe that's why it does not go through the callback beforeSave.

Here are some of the codes:

link

//formulario
<html>
<body>
<?php
   echo $this->element('menuReceitas');
?>

<?php
   echo $this->Form->create('Receita, array('type'=>'post'));
   echo $this->Form->hidden('id_receita');
   echo $this->Form->input('receita', array('label'=>'Receita','readonly'=>'readonly'));
   echo $this->Form->input('valor_receita', array('label'=>'valor'));
   echo $this->Form->input('data_receita', array('label'=>'Data', 'type'=>'text'));
   echo $this->Form->input('detalhamento', array('label'=>'Detalhamento', 'readonly'=>'readonly'));
   echo $this->Form->end("Alterar");
?>
</body>
</html>

//model

public function beforeSave() {
   $this->data['Receita']['valor_receita'] = $this->valor($this->data['Receita']['valor_receita']);
   $this->data['Receita']['data_receita'] = $this->data($this->data['Receita']['data_receita']);

   return true;
}

//controller

public function alterar($idReceita) {
   if ($this->request->is('get')) {
      $this->Receita->id = $idReceita;
      $this->request->data = $this->Receita->read();
   } else if ($this->request->is('post')) {
      $this->Receita->id = $idReceita;

      if ($this->Receita->save($this->Receita)) {
         echo $this->Session->setFlash("Receita alterada");
      } else {
         echo $this->Session->setFlash("Receita não alterada");
      }
   }
}
    
asked by anonymous 07.02.2016 / 19:14

1 answer

0
Under the wipes, CakePHP sets the form request to PUT.

So, in the else if statement ... change the is ('post') to is ('put') .

    
10.02.2016 / 18:57