What is the equivalent to getLastInsertId() in Cakephp?

后端 未结 22 703
囚心锁ツ
囚心锁ツ 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:21

    You can get last inseted id with many ways.Like Model name is User so best way to fetch the last inserted id is

    $this->User->id; // For User Model
    

    You can also use Model function but below code will return last inserted id of model with given model name for this example it will return User model data

    $this->User->getLastInsertId();
    $this->User->getInsertID();
    

提交回复
热议问题