【发布时间】:2009-06-11 06:58:40
【问题描述】:
如果我在save() 之后立即执行getLastInsertId(),它会起作用,否则不会。这在我的控制器中得到了演示:
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
}
请提出一种获得我想要的功能的方法。
【问题讨论】:
-
如果您想在不同的方法中使用插入 ID,那么您需要将其存储在某个地方,即会话或作为同一请求的一部分作为控制器中的类属性。
标签: cakephp