I'd be interested in seeing it too.

Personally I make a _addedit($id) action in my controller, and a
_addedit.thtml element (in with the normal view files).  These have the
common parts of add and edit in them.  I'm not sure if this will stay
this way once I start serious work on the application UI, but we are
still adding features (including new models, and changing model fields)
at this stage, and this does make it faster to keep things updated.

ie: UsersController:

        function add() {
                $this->_addedit();
        }

        function edit($id) {
                $this->_addedit($id);
        }

        function _addedit($id=null)
        {
                if ( !empty($this->params['form']['cancel']) ){
                        $this->Session->setFlash('The User was not saved');
                        $this->redirect('/users/index');
                        return false;
                }

                if(empty($this->data)) {
                        if ( empty($id) ){
                                // give default values
                        } else {
                                // add the associated models for the edit view
                                $this->_read_associations( $id );
                                $this->data = $this->User->read(null, $id);
                        }

                        $this->render();
                } else {
                        $this->cleanUpFields();

                        if($this->User->save($this->data)) {
                                $this->Session->setFlash('The User has been 
saved');
                                $this->redirect('/users/index');
                        } else {
                                $this->Session->setFlash('Please correct errors 
below.');

                                if ( !empty($id) ){
                                        $this->_read_associations( $id );
                                }
                        }
                }
        }


Both views/users/add.thtml and views/users/edit.thtml have

echo $this->renderElement('../users/_addedit');

in them, which renders the views/users/_addedit.thtml element - this is
what has all the actual form values.  It only has the common form
elements, as you often want some differences between the add and edit
forms.

I also have a views/users/_associated.thtml , which displays the
associated models (like what you normally see on the "view" template).
I like these associations to also be shown when editing, so again it's
a bit simpler to keep in a separate element.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to