I am trying to allow users to edit their account details but had the following error. ( I am new to Cake...)
The error is "Fatal error: Call to a member function user() on a non-object in /home/www/7b8dad242e3d067ccc5448180944bdab/web/shop/Controller/UsersController.php on line 79"
VIEW: (edit.ctp)
<?php echo $this->Form->create('User');?>
<fieldset>
<legend><?php echo __('Edit Details'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('name');
echo $this->Form->input('surname');
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->input('street');
echo $this->Form->input('number');
echo $this->Form->input('zipcode');
echo $this->Form->input('city');
echo $this->Form->input('country');
echo $this->Form->input('tel');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>
*CONTROLLER (UsersController.php) * line 79 is second line of code
public function edit($id = null) {
if($this->Auth->user() && $this->Auth->user('id') == $id) {
$this->User->read(null, $id);
$this->User->set(array(
'name' => $this->data['User']['name'],
'surname' => $this->data['User']['surname'],
'email' => $this->data['User']['email'],
'street' => $this->data['User']['street'],
'number' => $this->data['User']['number'],
'city' => $this->data['User']['city'],
'zipcode' => $this->data['User']['zipcode'],
'country' => $this->data['User']['country'],
'tel' => $this->data['User']['tel'],
));
$this->User->save();
}
}
* auth method
*
* @return void
*/
public function auth() {
$auth = $this->User->find('first', array(
'conditions' => array('User.email' => $this->request->data['email'], 'User.password' => $this->request->data['password'])));
if($auth == null) {
$this->Session->setFlash('Incorrect user or password', 'default', array(), 'auth');
$this->redirect(array('action' => 'add'));
} else {
$this->Session->write('logged_user', $this->request->data['email']);
//debug($_SESSION['logged_user']);
$this->redirect(array('controller' => 'products', 'action' => 'index'));
}
}
/**
Any suggestions will be more than welcome. Many thanks