I do this all the time especially for "administrative" models that super
users and admins can manage the settings and contents of those items for
elsewhere in the app. Each is very simple with only a few fields. The first
few lines of your edit.ctp view might look something like...
<?php
$session->flash();
echo '<H3>' . $this->pageTitle = ucfirst($this->action) . ' Item') .
'</H3>';
echo $form->create('Item', array('class' => 'stdform'));
echo $form->hidden('id');
/* all your regular editable or new item fields in here + a submit button
if you were feeling devious, you could put in branching based on the
contents of this->action but ideally this should be avoided. */
echo $form->end();
?>
IIRC, if it is an add() action, where form->hidden(ID) renders as "nothing",
cake is clever enough to write out the form action as /items/add. If an ID
is supplied, with the edit() action, cake figures it needs to go to
/items/edit. Simple :-)
Most of this is in the book and picked up on various blogs etc.
On Mon, Nov 10, 2008 at 4:46 PM, Shogun <[EMAIL PROTECTED]> wrote:
>
> hi!
>
> > Most obviously, the add() and edit() functions can often be the same
> form,
> > if the view is coded carefully and conforms to cake standards. Use
> > something like $this->render('edit') within the add() method.
> Alternatively,
> > don't have a specific add method and have your edit method assume that no
> > supplied ID means a new one. That might work in your circumstances, or
> maybe
> > not.
>
> this is exactly what i need... my question is, how would you detect in
> your view whether you are showing the "edit" o "add" form?
> i mean, what would be the right way to do it?
>
> thank you!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---