1

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?

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

2 Answers 2

0

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.

0

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');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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