XF 2.1 lastInsertId() issue

grantus

Active member
Is there a way to use something like lastInsertId() after doing a save?

For example, how can I get the last id that was just inserted here?

Code:
$form = $this->formAction();

$form->basicEntitySave($store, $input);
        
return $form;
 
Take a look at XF\Mvc\FormAction to better understand form actions.

Tl;Dr

PHP:
$form->complete(function ($form) use ($store) {
    // get the id of the entity that was saved
    $entityId = $store->getEntityId();
    // get the last insert id (might be smth. completely different or even 0)
    $lastInsertId = \XF::db()->lastInsertId();
});
 
Back
Top Bottom