1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cannot load class using XFCP

Discussion in 'XenForo Development Discussions' started by Helmut2509, Feb 19, 2014.

  1. Helmut2509

    Helmut2509 Member

    I have created a listener with the following code:
    if ($class == 'XenForo_Visitor')
    {
    $extend[] = 'AvatarGallery_Visitor';
    }

    ...the new class:
    class AvatarGallery_Visitor extends XFCP_AvatarGallery_Visitor
    --

    However, I get this error:

    An exception occurred: Cannot load class using XFCP. Load the class using the correct loader first. in ......library/XenForo/Autoloader.php on line 108
    ---
    what is wrong here?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    What code event did you use for your listener?
     
  3. Daniel Hood

    Daniel Hood Well-Known Member

    In your listener function did you have the & before the $extend paramater?

    PHP:
    public function listen($class, &$extend)
    {
    if (
    $class == 'XenForo_Visitor'
    {
    $extend[] = 'AvatarGallery_Visitor';
    }
    }
     
  4. Helmut2509

    Helmut2509 Member

    yes
     
  5. Helmut2509

    Helmut2509 Member

    I have a function "load_class_controller" extending two classes, and a function load_class_view ,extending one more class.
    I already changed the execution order, but without any effect.
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    XenForo_Visitor isn't a controller. So it won't work with a load_class_controller event.

    You might have more luck with a new code event listener that uses the load_class event. Though I'm not entirely sure if it is possible to extend XenForo_Visitor.

    It depends on what you want to do but another option is to use the visitor_setup event. That gives you access to the visitor object.
     
  7. Helmut2509

    Helmut2509 Member

    thanx for the tipp. Now I have this code:

    public static function load_class($class, array &$extend)
    {

    if ($class == 'XenForo_Visitor')

    {
    $extend[] = 'AvatarGallery_Visitor';
    }
    }

    ..and in the class AvatarGallery_Visitor I implemented a modified function of 'canUploadAvatar'.
    this is called by : $params['canUploadCustomAvatar'] = $visitor->canUploadAvatar(true);

    ..but unfortunately the call goes to the parent class and not to the extended class. So I am stuck again :-(
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    What is in the "canUploadAvatar" function? Generally permission checks aren't done like that.
     
  9. Helmut2509

    Helmut2509 Member

    I have to differenciate two cases: uploading an avatar from a gallery and uploading a user (custom) avatar.
    so I modified the function in the extended class

    public function canUploadAvatar($withCustomAvatar)
    {
    $uploadOk = (
    $this->_user['user_id']
    && $this->hasPermission('avatar', 'allowed')
    && $this->hasPermission('avatar', 'maxFileSize') != 0
    );
    if(!$uploadOk){
    return false;
    }

    if($withCustomAvatar && $this->hasPermission('avatar', 'uploadCustomAvatar')){
    return true;
    }
    return false;
    }
    ..but the problem is not the permission, but the fact, that the call goes to the parent class and not to the extended one.

    ...I now realized that I forgot to add the listener to the ACP list of code event listeners. Things look better now...
     
    Last edited: Feb 19, 2014

Share This Page