On Tue, Jan 22, 2013 at 5:48 AM, Sam <lightaiyee@gmail.com> wrote:
> Dear CakePHP experts,
>
> I just got a scolding for unfriendly software. This is my problem. Please
> help me if you know how to. Customer wants to add new records to database.
> The new records are very similar to existing records. Just need to change
> only 1 field. But currently, they have to re-keyin all the fields to add
> this new record.
>
> I would like to modify the edit feature such that instead of editing, it
> adds a new record when the user click the Submit button. This is because the
> values of existing record appears inside the fields. User only needs to
> modify one field, then click Submit.
>
> My add and edit functions are generated from Cake Bake. I am using CakePHP
> ver2.2
FormHelper will fill in the form fields if $this->request->data
contains data for that field. So, when editing, you would have this in
the controller action:
$this->request->data = $this->Model->read(null, $id);
For your add action, you could do something similar. Perhaps the best
approach would be to fetch the last inserted record and unset the id
as well as the field that the client will be changing for a new
record.
$data = $this->Model->find(
'first',
array(
'order' => array('Model.created' => 'DESC')
)
);
unset($data['Model']['id']);
unset($data['Model']['the_field']);
$this->request->data = $data;
--
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 post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment