My (mostly technical) blog

CakePHP: Edit view mysteriously changing to Add on Save validation failure

Posted on: March 25, 2009

I have never been more in need of a proper PHP debugger in my whole life. I have been stuck with a very mysterious behavior with CakePHP for the past 4 hours.

I was editing a model, then saving it. For some reason, my form action was changing from

/controller/edit/1
to
/controller/add

it was making me go crazy!

After seaching around (finally) I found this: https://trac.cakephp.org/ticket/5871
I came to realize that I have actually omitted the

<?= form->input('id'); ?>

from my edit view because I thought “why the hell do I need to edit the primary key?”

As it turns out, CakePHP needs a field (hidden or not) with the name ID or else it will revert to the ADD form.

Luckily though, it is smart enough to render it as a hidden field.

Google is your friend.

Advertisements
Tags: ,

8 Responses to "CakePHP: Edit view mysteriously changing to Add on Save validation failure"

Your last words “Google is your friend” reminds me of an article I read somewhere before. Was about 30 essential references for developers…

Google was #1 😀

Have you tried FirePHP with Firebug?
http://www.firephp.org/

Yeah I started using it recently..but I meant a “proper” debugger..that I can put breakpoints and follow through the execution line by line..!

It was happening somewhere automatically in the CakePHP framework source code so I couldn’t determine the reason directly by using FirePHP..

I just thought..it is just too odd to find on Google, but I guess I was wrong 😛

Thanks for posting. Wish the manual explained this a bit better.

What’s the last date I can post this to to arrive in time for Christmas? hot models
212650

I’d like to cancel a cheque 16yr Model Nn
=-[

I’m training to be an engineer Ls Models Foto
tqlkve

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Ahmed Sabbour's Facebook profile
March 2009
S M T W T F S
« Oct   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  

Tweets

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

RSS StackOverflow

Recently bookmarked

%d bloggers like this: