2

I need to execute some PHP code on every admin view/action. E.g

file_put_contents('somelogfile.log', 'I just executed admin action');

Where should I put this code so that it wont be swept away when I should upgrade my Joomla?

Joomla version is 3.8.6.

  • Best place I could come up with is theme template src/administrator/templates/isis/index.php but it does not execute on actions and allegedly executes AFTER component view. I need it to run at the very beginning. – JohnSmith Jul 12 '18 at 15:13
3

You can create a plugin. See https://docs.joomla.org/J3.x:Creating_a_Plugin_for_Joomla

Joomla automatically calls enabled Plugins on each trigger event.
Depending on the state the application has to be in for your code to be executed, you can choose the appropriate trigger event. See https://docs.joomla.org/Plugin/Events

There are also existing plugins that allow you to just place your code in the configuration interface in the backend. I haven't tried those though and I don't know if they work on every event.

  • But what about if I just want to register some autoloader or include some libraries? Still plugin? – JohnSmith Jul 17 '18 at 11:53
  • A Plugin is the most independent way. Of course you can add it to the main index.php of the Joomla installation, but it might be gone after a Joomla-Update. Or you put it in your Template, if you only need it there. If you need it in your own component, put it into the main file, named after the component. It depends on your goal. – Javatasse Jul 17 '18 at 14:15

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.