What is the equivalent to getLastInsertId() in Cakephp?

后端 未结 22 705
囚心锁ツ
囚心锁ツ 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条回答
  •  庸人自扰
    2020-11-28 11:33

    When you use save(), the last insert ID is set to the model’s $id property. So:

    if ($this->Model->save()) {
        printf('Last insert ID was %s', $this->Model->id);
    }
    

提交回复
热议问题