什么是相当于getLastInsertId()在Cakephp? [英] What is the equivalent to getLastInsertId() in Cakephp?
本文介绍了什么是相当于getLastInsertId()在Cakephp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在 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
}
请建议一种方法来获得功能I
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
这篇关于什么是相当于getLastInsertId()在Cakephp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文