Class 'ContentHelperRoute' not found

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
User avatar
bascherz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 243
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Class 'ContentHelperRoute' not found

Post by bascherz » Fri Apr 20, 2018 1:15 am

The following code is in a plugin I just wrote. It works perfectly on one of my sites but causes an error on the other site. Both sites are running on the same server in the same hosting account with all the same system configuration. The sites are even setup nearly identically, even using the same template configured the same way. I can't think of why it would work in one case and not the other.

The following code is in an event handler for the onContentAfterSave event for my plugin. &$article is one of the parameters passed in.

Code: Select all

$article_link = JURI::base().JRoute::_(ContentHelperRoute::getArticleRoute($article->id,$article->catid));
Here's the error I get on one site but not the other (the above call works on the other site):

Code: Select all

Class 'ContentHelperRoute' not found
Can anyone tell me what could cause the above error? Clearly, the same plugin installed on two nearly identical sites should work on both sites, right?

Thanks in advance,
Bruce

Edit: Something just hit me while I was typing that. On the site it is working, I was editing my article on the site front end and on the other I was editing on the back end. So I tried editing the article in the back end on both sites and the error occurs on both sites in that case. So it would seem that class ContentHelperRoute is not being loaded when in the admin back end of the site. Interesting. Is that something that should be fixed in the core or should my plugin be doing something to prevent it?

I added the following line to prevent this error, but this is not needed if the article is being edited on the site front end. This prevents the error from occurring, but now the generated link is completely wrong.

Code: Select all

if(!class_exists('ContentHelperRoute')) require_once (JPATH_SITE . '/components/com_content/helpers/route.php');
Bruce Scherzinger

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1009
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

Re: Class 'ContentHelperRoute' not found

Post by SharkyKZ » Fri Apr 20, 2018 7:36 am

bascherz wrote: I added the following line to prevent this error, but this is not needed if the article is being edited on the site front end. This prevents the error from occurring, but now the generated link is completely wrong.

Code: Select all

if(!class_exists('ContentHelperRoute')) require_once (JPATH_SITE . '/components/com_content/helpers/route.php');
Can you post examples of links generated before and after you added the code?

User avatar
bascherz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 243
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: Class 'ContentHelperRoute' not found

Post by bascherz » Fri Apr 20, 2018 12:56 pm

More detail. Sorry, I was rushed yesterday. I know you need this.

J! version: 3.8.6 (just updated to .7, no change)

There was no link before adding that last require_once line. The plugin was crashing on article saves in the back end because the class wasn't found. But, below shows the difference between the link produced when the plugin is triggered by saving an article from the front end vs. the back end with that require_once line inserted. These are both from saving the very same article. Please note I have SEF URLs enabled in global config.

Front:

Code: Select all

https://mydomain.com//home-sp-1432435916/hoa-board-news/this-is-a-test-article
Back:

Code: Select all

https://mydomain.com/administrator//administrator/index.php?option=com_content&view=article&id=74&catid=160
I added a line following the one that generates the link to remove "/administrator" from it and then both of the links do go to the correct article.

Code: Select all

https://mydomain.com//index.php?option=com_content&view=article&id=74&catid=160
But shouldn't this work the same in the front and back?
Bruce Scherzinger

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1009
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

Re: Class 'ContentHelperRoute' not found

Post by SharkyKZ » Fri Apr 20, 2018 1:18 pm

Routing between admin and site doesn't work yet https://github.com/joomla/joomla-cms/issues/20070.

It might get implemented in 3.9 https://github.com/joomla/joomla-cms/pull/16879.

But that will probably require changes in ContentHelperRoute too for this to work properly.

User avatar
bascherz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 243
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: Class 'ContentHelperRoute' not found

Post by bascherz » Fri Apr 20, 2018 2:08 pm

Awesome. Thanks for the info. Hope this was helpful. I at least have a solution that works now. I'll look forward to 3.9.
Bruce Scherzinger

User avatar
bascherz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 243
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: Class 'ContentHelperRoute' not found

Post by bascherz » Sat Apr 21, 2018 5:45 am

Just realized I am having a similar problem with content preparation. I posted about this elsewhere in these forums (viewtopic.php?f=727&t=961192), but at the time I had that problem I was only saving articles in the back end editor. I just tried editing one in the front end that uses the loadposition plugin and content.prepare worked. So it would appear there are many content things that don't render properly in the back end based on what I read at the URLs you provided, SharkyKZ. Guess I have to hope for all this stuff to be resolved in 3.9.

I'll end it here so it doesn't go off in a different direction. Thanks again for the info, SharkyKZ.
Bruce Scherzinger


Post Reply

Return to “Joomla! 3.x Coding”