我想在保存产品后将产品ID放入会话中,但是当我阅读会话时,我得到了错误的ID。
foreach ($this->data['Address'] as $key => $ab) {
$this->data['Product'][$key]['model'] = 'User';
$this->data['Product'][$key]['foreign_key'] = $this->User->id;
$this->Supplier->Brand->Type->create();
$this->Supplier->Brand->Type->save($this->data['Product'][$key]);
$this->Session->write('productId', $this->Supplier->Brand->Type->id);
}
如何获取产品ID?
答案 0 :(得分:0)
尝试使用代码
foreach ($this->data['Address'] as $key => $ab)
{
$this->data['Product'][$key]['model'] = 'User';
$this->data['Product'][$key]['foreign_key'] = $this->User->id;
$this->Supplier->Brand->Type->create();
$this->Supplier->Brand->Type->save($this->data['Product'][$key]);
$lastid = $this->Supplier->Brand->Type->getLastInsertID()
$this->Session->write('productId', $lastid);
}