4

I've read the Exception methods in order to replace the deprecated JError, but I can't solve the following problem:

I have a plugin that redirects an user to a login page in case he/she tries to access a page that is for a logged-in user (instead of getting the message "You are not authorised to view this resource.").

It used to work when JError was still around (before J3), the code was like this:

Error::setErrorHandling(E_ERROR, 'callback', array(
    'plgSystemCustom_Redirects',
    'handleError'
));

And in the rest of the script I had the handleError function.

My doubt here is (unlike any other examples that I've read) how to catch the error (I'm not able to issue a try); in other words, how to replace the deprecated code with something that works in Joomla 3.5?

  • I've made some research on this question, it seems that there isn't a class to replace JError, so for now we just have to use the deprecated JError.. – Kitase88 Apr 15 '16 at 17:39
  • @NicolaCiciliot but JError no longer works, that's the problem! – jackJoe Apr 16 '16 at 13:39
  • Actually JError is still widely used in Joomla core and extensions, also the default error page in system template is still written with JError, so it must be something else that mess up your plugin – Kitase88 Apr 18 '16 at 6:52
  • @NicolaCiciliot JError may work, but setErrorHandling doesn't. I have no other way to handle the errors in the same way as before. – jackJoe Apr 18 '16 at 9:47
3

There is no alternative to JError and JException classes, Joomla development decided to remove those classes and use php exception instead. Take a look at the deprecated JError table.

So on my opinion you have two possible ways:

  • Rewrite your plugin with php exception handler
  • Rethink your plugin using JLog class

Here are some interesting discussions and resources on this topic:

Hope this will help you.

  • Nice answer! I will try some of your suggestions and post a feedback here. – jackJoe Apr 18 '16 at 17:56
  • Let me know your results, cause I also still use JError in my components! – Kitase88 Apr 20 '16 at 6:24
0

Since Joomla 2.5 and in Joomla 3.5, you can use the mothods descripted in https://docs.joomla.org/Auto_redirect_guests_to_login to manage your feature, there is no need to add a plugin! I use this at my site https://www.loytec.com, see Menu Support>ProductReturn(RMA) https://www.loytec.com/support-en/rma with Joomla Core tools only.

  • Thanks for the reply, although that has nothing to do with my request, also I cannot make a menu for each protected content/article, so that solution wouldn't work here. – jackJoe Apr 3 '16 at 19: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.