If I do getLastInsertId()
immediately after a save()
, it works, but otherwise it does not. This is demonstrated in my controller:
f
I think it works with getLastInsertId()
if you use InnoDB Tables in your MySQL Database. You also can use $this->Model->id
$this->Model->field('id', null, 'id DESC')
You'll need to do an insert (or update, I believe) in order for getLastInsertId()
to return a value. Could you paste more code?
If you're calling that function from another controller function, you might also be able to use $this->Form->id
to get the value that you want.
Use this one
function designpage() {
//to create a form Untitled
$this->Form->saveField('name','Untitled Form');
echo $this->Form->id; //here it works
}