我正在尝试编辑公司并更新umusers表中的密码。如果我使用save,它会更新公司,但不会更新umusers表中的密码。如果我使用saveAll,它会在umusers表中创建一个新用户。
这是我的设置
公司模式我:
public $hasOne = 'Umuser';
公司控制人
public function edit($id = null) {
$this->Company->id = $id;
if (!$this->Company->exists()) {
throw new NotFoundException(__('Invalid company'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Company->save($this->request->data)) {
$this->Session->setFlash(__('The company has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The company could not be saved. Please, try again.'));
}
} else {
$this->request->data = $this->Company->read(null, $id);
}
}
$ this->请求 - >数据的var_dump:
array(2) { ["Company"]=> array(12) { ["id"]=> string(3) "157" ["member_number"]=> string(6) "234234" ["name"]=> string(5) "keith" ["address1"]=> string(5) "keith" ["address2"]=> string(5) "keith" ["county"]=> string(5) "keith" ["limited"]=> string(1) "0" ["tax_number"]=> string(5) "keith" ["contact_name"]=> string(5) "keith" ["phone"]=> string(5) "keith" ["email"]=> string(15) "keith@keith.com" ["payment_start"]=> array(3) { ["month"]=> string(2) "02" ["day"]=> string(2) "01" ["year"]=> string(4) "2013" } } ["Umuser"]=> array(1) { ["password"]=> string(6) "keith1" } }
我知道目前我没有哈希密码或者如果留空则取消设置密码。我错过了什么,或许与id的关系?
答案 0 :(得分:1)
In this you need to get the "umuser id" & specify the id value as below..
{
["Company"]=> {
["id"]=> "157"
......
}
["Umuser"] => {
["id"]=> "some value"
["password"]=> "keith1"
}
}
答案 1 :(得分:0)
请确保您已在编辑表单中将id作为隐藏字段传递。
echo $this->Form->input('id', array('type' => 'hidden'));