On May 14, 5:05 pm, Thomas Ploch <[email protected]> wrote:
> I suppose that:
>
> a) The hidden input for Model.id is missing from the edit form.
> b) The record isn't being read in the action beforehand
>
It isn't missing. the edit action receives it as a parameter. It's in
the URL! admin/edit/345
The update itself works fine. I just need to do something else in
beforeSave().
public function admin_edit($id = null) {
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
if ($this->request->isPost() || $this->request->isPut()) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(sprintf(__('The user has been
saved, password: %s', $this->User->cleartext_password)));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be
saved. Please, try again.'));
$this->set('errors', $this->User->validationErrors);
}
} else {
$this->request->data = $this->User->read(null, $id);
unset($this->request->data['User']['password']);
}
}
but then I can't get at the id field to check if we're creating or
saving.
public function beforeSave() {
$data = &$this->data[$this->alias];
var_dump($data); exit;
if (empty($data['id'])) {
// do when adding
} else {
// do when editing
}
return true;
}
How?
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php