0

I'm trying to figure out how to run a function/script as soon as an item is saved in joomla 2.5. Joomla's MVC structure is still rather complicated to me so I'm pulling my hair here trying to find out where this save event is triggered. Also I want to keep the code neat so I'm asking here for help.

Basically I want to run my own function (let's say emailUser() ) as soon as an item is saved in joomla. Currently there is no way for me to do "other stuff" when the save event is triggered.

I'm using a custom component generated with the component creator here: http://www.notwebdesign.com/joomla-component-creator/

I heard that plugins are the solution, but I can't find any documentation on the save events and how to use a plugin to do this. Joomla's help forums aren't helping either. So basically I need a push in the right direction.

EDIT: I've seem to found the toolbar which creates the save button, but that means that it's saved through the internal workings of joomla. It's in the view.html.php file. Any way of tapping into that with a custom function?

Techie
  • 44,706
  • 42
  • 157
  • 243
Nick
  • 2,862
  • 5
  • 34
  • 68

2 Answers2

0

Inside the controller of the component (administrator/components),how about redefining the save event to be something like this:

$save =& JToolBarHelper::save('clientscan.save', 'JTOOLBAR_SAVE');
if($save)
{
    JFactory::getMailer();
    //emailing goes here..
}
foxns7
  • 518
  • 2
  • 7
  • 18
  • I could use the mailer method, however I'm curious as to **where** I should call this method. I'm scouring through the source of the generated component and I can't quite make out where I can run a new function right after an item is saved (it's just the event I'm looking for) – Nick Dec 28 '12 at 17:20
  • I don't know much about this component creator, but conceptually, it should be inside the administrator directory where you may have some subdir like components/modules. From there, your focus is narrowed down to the component's structure itself. The save event should be somewhere within the controller part. – foxns7 Dec 28 '12 at 17:39
  • I've looked and it seems to be an internal joomla helper. `JToolBarHelper::save('clientscan.save', 'JTOOLBAR_SAVE');` So yeah.. no idea what to do now since modifying joomla's internals is not an option :') – Nick Dec 28 '12 at 17:51
  • sorry for the uber late response, but it doesn't seem to work. This only creates the button. That actual save function is hidden somewhere deep in the belly of joomla. Everything is automated by the arguments passed in the URL so it's really difficult (as far as I know) to get this going.. I'll ask again on the joomla forums – Nick Dec 30 '12 at 18:57
  • Not deep at all and as I said it offers a postsavehook. – Elin Dec 31 '12 at 03:30
0

After save would say use a postSaveHook in your controller.

Elin
  • 6,507
  • 3
  • 25
  • 47