Php 将id保存到会话
我想在保存产品后将产品Id放入会话,但在读取会话时,我得到了错误的IdPhp 将id保存到会话,php,cakephp,Php,Cakephp,我想在保存产品后将产品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->
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?请尝试使用代码
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);
}
您正在保存集合中的最后一个id,因为每个连续循环都会覆盖上一个循环。这不是你想要的吗?是的,我想要最后一个身份证。。。。