3

I am modifying a component. In its model file, it creates a class that extends JModelAdmin. In its save() function, it takes form data, then calls parent:save(). I am trying to get the id of the newly added row.

I am new to joomla, but I know the $this variable should contain relevant info. $this->id does not return the newly created id, but rather, 0. I think this makes sense since $this would not know about the id created in the parent save function.

So what do I do to get the id from the parent save?

Thanks! Brian

5

It is saved in the model state. You can retrieve it with:

$this->getState($this->getName() . '.id');
0

Nevermind. Figured it out after some more research.

$this->getState($this->getName().'.id')

Man, there are some convoluted posts out there about how to do this! Glad I found something this elegant!

  • Please remove this identical answer because @Anibal answered it one minute sooner than you :) – Farahmand Apr 7 '15 at 6:40

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.