4

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

2 Answers 2

7

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!

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

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.