An example might clarify (note this isn't syntactically perfect, I'm
writing this by hand):
In my ADD view:
$form->create('Game');
$form->input(blahblah); // your input fields
$form->end('Add');
outputs -->
<form id='GameAddForm' action='games/add' method='post'>
The input fields here
<input type='submit' value='Add'/>
In my EDIT view:
$form->create('Game');
$form->input(blahblah);
$form->end('Update');
outputs -->
<form id='GameEditForm' action='games/edit' method='post'>
The input fields here
<input type='submit' value='Update'/>
Notice that the code to generate the forms is the same. The model name
is specified on the form->create. Cake has decided that the form
should self post, so the action is derived from the controller/view
that created it.
If the input fields contain a field (normally hidden) which is the
model's key (id='GameId' name='data['Game']['id'] in this example)
then, when the controller saves the data, that record would be
updated. If this field is not in the form then an insert would be
performed. Basically the EDIT and ADD action code in the controller is
the same.
Sorry if I have this wrong. I will be mortally embarrased for causing
confusion. I have only been using Cake for about 8 weeks (loving it)
but I'm quite confident.
Sid. (the nervous)
On Feb 18, 7:50 pm, Aivaras <[email protected]> wrote:
> Unless you create a form with Model.id that is filled by edit() function.
> You don't need to specify an action then.
>
> Aivaras
>
> On Wed, Feb 18, 2009 at 10:35, RichardAtHome <[email protected]>wrote:
>
>
>
> > Sindey, Marcelo is right. The default action for a form is to post to
> > the $controller->add() method. You have to override it for other
> > actions
>
> > On Feb 18, 12:00 am, Sidney <[email protected]> wrote:
> > > I think the default action is to self-post i.e. the form post/get goes
> > > to the same controller/action that served the view with the form on
> > > it. This is a normal design convention and seems logical to me
> > > (although quite a noob myself). Perhaps I misunderstand your question?
>
> > > On Feb 17, 8:01 am, Marcelo Andrade <[email protected]> wrote:
>
> > > > Hi there,
>
> > > > By the CakePHP conventions, the view's name must be the same
> > > > as an action in a controller. A common mistake for the newbies is
> > > > when creating a form in the view is that the
>
> > > > echo $form->create('MyModel');
>
> > > > defaults to generate a form for the "add" action. But I think that
> > > > should be more intuitive that it's defaults to the action with the
> > > > same name as the view. Isn' it?
>
> > > > Best regards.
>
> > > > --
> > > > MARCELO DE F. ANDRADE (aka "eleKtron")
> > > > Belem, PA, Amazonia, Brazil
> > > > Linux User #221105
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---