Friday, April 26, 2013

Re: POST and PUT problems on add action

Yes, its the correct way to solve...

POST is when you are creating a new record, and PUT is when you are updating a record...
*¹  Cake doesnt uses really the PUT method, but a hidden field with the method. (I think it´s because most browsers doesnt support PUT method)
*²  When a validation error occurs, the request data is populated, so cake recognize as you are updating, not creating a new data... That´s why when you click once "send button" it will use the PUT method.

I hope it helps

Em sexta-feira, 26 de abril de 2013 12h50min58s UTC-3, Martin Aguilar escreveu:
I'm new to cakephp and I'm start loving it but today I had a problem on adding new data (action add).
After baking users table the result was
public function add() {  	if ( $this->request->is('post') ) {  


I had add some validation on my model to names and more fields. The first push on submit button show invalid validation messages but on second click on submit did nothing.
I found that the  $this->request->is('post') becomes false after first submit. I look on edit action and I see that also ask for put.

to solve this problem all I had to do was

public function add() {  	if ( $this->request->is('post') || $this->request->is('put') ) {

It's working fine now for me and to to solve it on every baking I personalized my baking template on my project
app/Console/Templates/myTemplate/actions/controller_actions.ctp

I really don't know if this is the correct way to solve it, I've never used PUT on PHP apps that I made and I don't see a big difference either way.
I comment this because I don't know if is a bug on cake (tested on version: 2.3.1 - 2.3.3 ).

I hope this information helps and also I hope to see some comments to understand a little bit more.

tags: flash session message validation post put

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: