I wrote a small joomla 4 component and made it possible to create a new item in the frontend.

After creating a new item, Joomla core components usually redirects to a list view. But I want to redirect to the detail view of the item.

For example /view=myitem&id=11:test&catid=3

Unfortunately I do not know the id of the new item at the time of creation. Therefore I can not create the URL while creating the item.

Is there a way to do this that I do not see?

  • Could you post the save method of your Model that saves the item?
    – pe7er
    Commented Mar 15, 2022 at 9:19

2 Answers 2


If you're extending core form controller/model, you can access the ID through the model in controller's postSaveHook() method:

protected function postSaveHook(\Joomla\CMS\MVC\Model\BaseDatabaseModel $model, $validData = [])
    $id = $model->getState($model->getName() . '.id');

Joomla 3's documentation for inserting data into a database https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase#Inserting_a_Record mentiones:

$new_row_id = $db->insertid();

The Joomla 4 code base still uses $db->insertid(); at some places, so I suppose that it will work for your code as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.