3

I am getting this line in the error_log of a Joomla! 3.6.5 site every so often:

[21-Dec-2016 18:29:41 America/Detroit] PHP Fatal error:  Class 'ContentHelperRoute' not found in /path/to/site/templates/theme/html/mod_articles_categories/default_items.php on line 14

Here are the contents of default_items.php:

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_categories
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

foreach ($list as $item) :
?>
    <li <?php if ($_SERVER['PHP_SELF'] == JRoute::_(ContentHelperRoute::getCategoryRoute($item->id))) echo ' class="active"';?>> <?php $levelup = $item->level - $startLevel - 1; ?>
        <a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($item->id)); ?>">
        <?php echo $item->title;?></a>
        <?php
        if ($params->get('show_description', 0))
        {
            echo JHtml::_('content.prepare', $item->description, $item->getParams(), 'mod_articles_categories.content');
        }
        if ($params->get('show_children', 0) && (($params->get('maxlevel', 0) == 0) || ($params->get('maxlevel') >= ($item->level - $startLevel))) && count($item->getChildren()))
        {
            echo '<ul>';
            $temp = $list;
            $list = $item->getChildren();
            require JModuleHelper::getLayoutPath('mod_articles_categories', $params->get('layout', 'default').'_items');
            $list = $temp;
            echo '</ul>';
        }
        ?>
 </li>
<?php endforeach; ?>

Here are the contents of the core default_items.php file for comparison:

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_categories
 *
 * @copyright   Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

foreach ($list as $item) : ?>
    <li <?php if ($_SERVER['REQUEST_URI'] == JRoute::_(ContentHelperRoute::getCategoryRoute($item->id))) echo ' class="active"';?>> <?php $levelup = $item->level - $startLevel - 1; ?>
        <h<?php echo $params->get('item_heading') + $levelup; ?>>
        <a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($item->id)); ?>">
        <?php echo $item->title;?>
            <?php if ($params->get('numitems')) : ?>
                (<?php echo $item->numitems; ?>)
            <?php endif; ?>
        </a>
        </h><?php echo $params->get('item_heading') + $levelup; ?>>

        <?php if ($params->get('show_description', 0)) : ?>
            <?php echo JHtml::_('content.prepare', $item->description, $item->getParams(), 'mod_articles_categories.content'); ?>
        <?php endif; ?>
        <?php if ($params->get('show_children', 0) && (($params->get('maxlevel', 0) == 0)
            || ($params->get('maxlevel') >= ($item->level - $startLevel)))
            && count($item->getChildren())) : ?>
            <?php echo '<ul>'; ?>
            <?php $temp = $list; ?>
            <?php $list = $item->getChildren(); ?>
            <?php require JModuleHelper::getLayoutPath('mod_articles_categories', $params->get('layout', 'default') . '_items'); ?>
            <?php $list = $temp; ?>
            <?php echo '</ul>'; ?>
        <?php endif; ?>
    </li>
<?php endforeach; ?>

How can I resolve this error?


Note: These errors only began on Nov 3, so I assume this was related to the 3.6.4 update or a minor update to PHP 5.5.

2
  • 1
    I recently got this error on a site I updated - but I can't recall what I did to fix it not even which site that was. If I manage to recall more on this case, I will post here.
    – FFrewin
    Commented Dec 26, 2016 at 7:49
  • the answer I posted is the solution to this issue and its a bug fix committed for future releases of joomla. Since many may arrive here with the same issues, accept the answer so they can see it is answered and to use the suggestion to resolve their issues.
    – FFrewin
    Commented Jan 31, 2017 at 20:35

2 Answers 2

3

I just came across this issue again with another site and remembered what the problem is. This module is that it has changed the way it's loading its helper File/Class and the way the helper.php file is loading the ContentHelperRoute Class, so the ContentHelperRoute isn't anymore available at the default_items.php template file.

From:

require_once __DIR__ . '/helper.php';

inside the mod_articles_categories.php to include the helper file and Class, and:

require_once JPATH_SITE . '/components/com_content/helpers/route.php';

inside the helper.php, to include the ContentHelperRoute file/Class, it now loads the said Classes with JLoader::register();

But this way the ContentHelperRoute isn't available anymore in the default_items.php where it's getting called.

To fix this bug, you can edit the mod_articles_categories.php and add this line after the defined('_JEXEC') or die;

JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');

Update

This is a bug as shown here: https://github.com/joomla/joomla-cms/pull/13590

You can apply the above fix to the mod_articles_categories.php and wait for the next Joomla release.

1
  • I have added that line. I will let you know if the error reappears. Commented Jan 26, 2017 at 18:33
0

It appears that recent versions of Joomla! have replace $_SERVER['PHP_SELF'] with $_SERVER['REQUEST_URI']. I have replaced that code on line 14 and will continue to monitor the error_log to see if the issue is resolved.


Update: I have received the same error at least once since this "fix", so it appears it did not solve the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.