I’m having a spot of problem with CakePHP 2.0.2. I’m wanting to create an “edit profile” action. Here’s my controller action:
public function edit_profile() {
if ($this->request->is('get')) {
$this->request->data = $this->User->findById($this->Auth->user('id'));
} else {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Your profile has been updated'));
}
}
}
And here’s my view:
<h2>Edit Profile</h2>
<?php
echo $this->Form->create('User');
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
echo $this->Form->input('email');
echo $this->Form->end('Save Profile');
?>
However, when I submit the form, nothing seems to happen. I get no success message, and I also get no error message. If I put an else statement to complement if ($this->User->save($this->request->data)), that code block is executed though, indicating the User model data is not saved.
Where am I going wrong?
Check $this->User->validationErrors in the else statement if the user is not saved. My bet is that you have extra validation rules defined that are failing for fields not in your form.