1

I have built a number of custom modules and they work fine as long as there is no error. The error trapping works fine too. The only issue that I have is that when using exit() to display a message and stop the php page from running - it displays the page outside of Joomla rather then in the module location.

You can see an example of this behavior at: http://www.p3proswing.com/site3/index.php/p3-live-home

I would want this error to appear within the main body of Joomla (like the module does when you are logged in). Thus, the header, menu, footer, etc. should all still be displayed.

  • @Lodder's answer below is the correct method for displaying error messages. Using an exit() statement in PHP causes all activity to stop, which looks like what you are experiencing. – Terry Carter Mar 18 '16 at 19:55
2

If you want to display error message, you can use Joomla's enqueueMessage function, like so:

$app = JFactory::getApplication();
$app->enqueueMessage('Oops - something went wrong', 'error');

Have a look at the bottom of the Documentation page to see what types of alerts can be used:

https://docs.joomla.org/Display_error_messages_and_notices

Hope this helps -- you will also want to not exit() the program, but gracefully stop whatever processing you are attempting, otherwise the Messages will not get displayed in the Joomla layout.

  • I had to modify it slightly to JFactory::getApplication()->enqueueMessage(message, type) as the above was giving an error that the enqueueMessage function was not found. But this led me to the answer. Then I used 'return' instead of 'exit()' to end script execution. Thanks folks. – Charles Wilkins IV Mar 21 '16 at 15:19
  • @CharlesWilkinsIV - Oh sorry, my bad. I fixed the code in the answer. Was simply changing $app> to $app-> – Lodder Mar 21 '16 at 15:23

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.