What is the equivalent to getLastInsertId() in Cakephp?

后端 未结 22 670
囚心锁ツ
囚心锁ツ 2020-11-28 11:00

If I do getLastInsertId() immediately after a save(), it works, but otherwise it does not. This is demonstrated in my controller:

f         


        
22条回答
  •  -上瘾入骨i
    2020-11-28 11:46

    You'll need to do an insert (or update, I believe) in order for getLastInsertId() to return a value. Could you paste more code?

    If you're calling that function from another controller function, you might also be able to use $this->Form->id to get the value that you want.

提交回复
热议问题