0
votes

I'm creating a products component in Joomla 2.5 and the client wants all the products to show up in a sub-menu to the existing menu item Products, this has to be done automatically through the products component.

The creation of products is done through Joomla's back-end through custom component views, controllers and models.

I can easily create the menu item given the product's id and name (for menu display title), my problem lies in obtaining the product id when I'm adding an entirely new product to the database. Is there any method in the controller or model that I can overload? Can this id somehow be obtained using some model method I've missed?

Cheers, grouse

1
Some actual detail would help... like what component... what does it support in terms of being extended, what have you tried...Craig
The component is custom, as stated in the original question, so what I can do with it is only limited to the Joomla framework. I've looked for any feature in the built in framework, in the models and components, that could give me the functionality that I need but neither the JModel nor JController seem to have anything that gives me the id of the last saved database row, as far as I've been able to tell.grouse

1 Answers

0
votes

Fixed by overloading the save method of JController and at the end do

$db = &JFactory::getDBO();
parent::save($key, $urlVar);
$id = $db->insertid();

if ($id == 0) { 
    $id = JRequest::getInt('id', 0);
}

Then passing the retrieved id to defined methods in the model and have the method perform the action necessary. Leaving this here for future reference to myself and others that might stumble across it.