Cakephp 中的 getLastInsertId() 等价于什么? [英] What is the equivalent to getLastInsertId() in Cakephp?
本文介绍了Cakephp 中的 getLastInsertId() 等价于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在 save()
之后立即执行 getLastInsertId()
,它会起作用,否则就不起作用.这在我的控制器中得到了证明:
If I do getLastInsertId()
immediately after a save()
, it works, but otherwise it does not. This is demonstrated in my controller:
function designpage() {
//to create a form Untitled
$this->Form->saveField('name','Untitled Form');
echo $this->Form->getLastInsertId(); //here it works
}
function insertformname() {
echo $this->Form->getLastInsertId(); //this doesnt echo at all
}
请提出获得我想要的功能的方法.
Please suggest a way to get the functionality I want.
推荐答案
CakePHP 有两种获取最后插入 id 的方法:Model::getLastInsertID()
和 Model::getInsertID()
.实际上这些方法是相同的,所以你使用哪种方法并不重要.
CakePHP has two methods for getting the last inserted id: Model::getLastInsertID()
and Model::getInsertID()
.
Actually these methods are identical so it really doesn't matter which method you use.
echo $this->ModelName->getInsertID();
echo $this->ModelName->getLastInsertID();
这些方法可以在 cake/libs/model/model.php
第 2768 行找到
This methods can be found in cake/libs/model/model.php
on line 2768
这篇关于Cakephp 中的 getLastInsertId() 等价于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文