我是使用 CakePHP 的新手,目前我正在尝试允许用户编辑它自己的个人详细信息。
但是尽管该功能似乎有效(它告诉我用户已更新)它实际上并没有更新用户的详细信息。
我在 $this->request->data 上使用了调试器,它似乎显示的只是登录用户的用户 ID。
这是我的功能
public function useredit() {
$this->User->id = $this->Session->read('Auth.User.id');
$this->request->data = $this->Session->read('Auth.User.id');
if ($this->request->is('post') || $this->request->is('put')) {
//debug($this->request->data);
//exit;
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
}
} else {
$this->request->data = $this->User->read(null);
isset($this->request->data['User']['password']);
}
}
这是我的看法:
<?php
echo $this->Form->create('User', array('action' => 'useredit'));
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->input('username', array('value' => $this->Session->read('Auth.User.username')));
//echo $this->Form->input('password');
echo $this->Form->input('name', array('value' => $this->Session->read('Auth.User.name')));
echo $this->Form->input('surname', array('value' => $this->Session->read('Auth.User.surname')));
echo $this->Form->input('address1', array('value' => $this->Session->read('Auth.User.address1')));
echo $this->Form->input('address2', array('value' => $this->Session->read('Auth.User.address2')));
echo $this->Form->input('town', array('value' => $this->Session->read('Auth.User.town')));
echo $this->Form->input('postCode', array('value' => $this->Session->read('Auth.User.postCode')));
echo $this->Form->input('dob', array ('value' => $this->Session->read('Auth.User.dob')
, 'label' => 'Date of Birth'
, 'dateFormat' => 'DMY'
, 'empty' => array('DATE','MONTH','YEAR')
, 'minYear' => date('Y') - 110
, 'maxYear' => date('Y') - 0));
echo $this->Form->input('emailAddress', array('value' => $this->Session->read('Auth.User.emailAddress')));
echo $this->Form->input('phoneNumber', array('value' => $this->Session->read('Auth.User.phoneNumber')));
echo $this->Form->input('mobileNumber', array('value' => $this->Session->read('Auth.User.mobileNumber')));
echo $this->Form->end('Submit');
?>
任何帮助找出为什么这不会保存除 id 以外的任何其他数据的任何帮助将不胜感激!
谢谢