Simple query not working: how to debug? [Solved]


#1

I’m on 2.6 CakePhp and I’d like to update field “stato” (an ENUM type field) on “customerbranches” table, and enter “closed” in it.

On VIEW I have this link:

echo $this->Form->postLink(__('Close'), 
         array(  'action' => 'close',
                     $customerbranch['Customerbranch']['id']),
                     array(  'confirm' => __('Sure?',))
             );

On CustomerbrachesController I have this, but it doesn’t update:

 public function close($id = null) {
       $this->Customerbranch->id = $id
           if ($this->Customerbranch->id) {
              $this->Customerbranch->saveField('stato', 'closed');
           }
 }

Any hint? Or how can I debug?


#2

Hey @tom1884it,

I would get the entity first and the save the desired filed right away. Yes, you use the saveField method, but have you checked the saveField() method API Docs for your Cake version?

https://book.cakephp.org/3.0/en/orm/saving-data.html#updating-data


#3

When you want to debug() your Cake App, just activate the

'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),

in the app.php and use debug($watzfoobar); in your Controller or Model or whereever you need it.

:v:


#4

Thank you for your support.
'Cause I already knew the $id, I thought to directly update field “stato” of that id row.
It seems I’m on Cake 2.6v.

Which “update” function can I use, sure it can work on any Cake version, instead of “saveField”? (even if I tried almost everything and I think it’s something not working…)


#5

I tried to put only a redirect inside the function and it is not working:

    public function close($id = null) { return $this->redirect(array('controller'=>'customers', 'action' => 'index')); }

What is wrong?! It’s seems like it totally ignore the postlink… even if it’s similar to a working “Delete” Form-postlink.

Please, I’m going crazy…


#6

Just got it. In the “head” of controller there was this line:

`$this->Auth->allow(‘subscription’, ‘paymentresponse’, ‘contractuploadreminder’, ‘stripe’);

I had to add my new function in the list, even if I don’t know if I have to protect it more.