1

我想在保存产品后将产品 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?

4

1 回答 1

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);
}
于 2012-04-11T16:13:27.543 回答