0

I am developing a custom component and when I try to call my view I am receiving this error. The error occurs at: .\components\com_engineering\views\commentform\tmpl\default.php:24

Here is line 23 and 24

$user    = JFactory::getUser();
$canEdit = EngineeringHelpersEngineering::canUserEdit($this->item, $user);

It was my understanding by using JLoader::register that Joomla would automatically load the helper when the class is needed. Either my understanding is incorrect or I am doing something wrong.

The following is what I am trying to do.

site/helpers/engineering.php

defined('_JEXEC') or die;

JLoader::register('EngineeringHelper', JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_engineering' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'engineering.php');

/**
 * Class EngineeringFrontendHelper
 *
 * @since  1.6
 */
class EngineeringHelpersEngineering
{
  public static function canUserEdit($item)
  {
    $permission = false;
    $user       = JFactory::getUser();

    if ($user->authorise('core.edit', 'com_engineering'))
    {
        $permission = true;
    }
    else
    {
        if (isset($item->created_by))
        {
            if ($user->authorise('core.edit.own', 'com_engineering') && $item->created_by == $user->id)
            {
                $permission = true;
            }
        }
        else
        {
            $permission = true;
        }
    }

    return $permission;
  }

  // other classes
}

Thanks for any help!

1

Short version. Move your jloader register statement into an earlier file like your controller or something.

Longer version. JLoader::register allows you to ask Joomla's autoloader to require the appropriate file when you call a class that hasn't been included/required (made available) yet. Once a file has been included/required in the code execution flow then all its classes and functions are available for use. When you call a class that is not available, php5+ will run through any registered autoloaders and ask them if they know where the class is and if so then to include the file and then continue with the original class call. Hence, it makes no sense for a file to register itself with the autoloader, because if that register statement runs then the file has already been included, thus its classes are available, thus the autoloader will never be asked to find the file of the class.

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.