Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将id保存到会话_Php_Cakephp - Fatal编程技术网

Php 将id保存到会话

Php 将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->

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

请尝试使用代码

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,因为每个连续循环都会覆盖上一个循环。这不是你想要的吗?是的,我想要最后一个身份证。。。。