2012-04-11 9 views
1

製品を保存した後に製品IDをセッションに入れたいのですが、セッションを読むときに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

あなたがセットの最後のIDを保存しているとしてみてください。それはあなたが望むものではありませんか? – JJJ

+0

はい私は最後のIDを取得したい.... – vnpnlz

答えて

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); 
} 
関連する問題