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

how to call to other add-on's method from my add-on using $this ?

Discussion in 'XenForo Development Discussions' started by Earl, Aug 2, 2016.

  1. Earl

    Earl Member

    I'm trying to add a custom inline mod option

    @Snog helped me with this code
    https://xenforo.com/community/threa...core-methods-with-addons.119132/#post-1086469

    but when the code gets executed, I get the error
    ( ! ) Fatal error: Call to undefined method MyAddon_Model_Post::canDeleteRating() in /var/www/html/library/MyAddon/Model/Post.php on line 15

    [​IMG]

    so the problem in this line:
    Code:
    if ($this->canDeleteRating($post, $thread, $forum, $null, $nodePermissions, $viewingUser))
    and its looking for a method in my addon, which has defined in the original post ratings addon:
    Code:
    class Dark_PostRating_Model extends XenForo_Model
    {
        public function canDeleteRating(array $post, array $thread, array $forum = array(), &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
        {
            $this->standardizeViewingUserReferenceForNode($thread['node_id'], $viewingUser, $nodePermissions);
    
            if (!$viewingUser['user_id'])
            {
                $errorPhraseKey = 'login_required';
                return false;
            }
            if ($post['message_state'] != 'visible')
            {
                return false;
            }
        
            return XenForo_Permission::hasContentPermission($nodePermissions, 'deleteRating');
        }
    }
    


    I need to run the check : "$this->canDeleteRating($post, $thread, $forum, $null, $nodePermissions, $viewingUser"
    before I add the option.
    Please help..
     
    Last edited: Aug 2, 2016
  2. katsulynx

    katsulynx Well-Known Member

    Make sure to set your Listener Execution order number above the one of the addon whose functions you need.
     
    Earl likes this.
  3. Earl

    Earl Member

    Did you mean this value?

    [​IMG]
    I changed it to "11"
    The main add-on has '10', but It's still giving me the same error :unsure:

    [​IMG]
     
    Last edited: Aug 2, 2016
  4. Earl

    Earl Member

    @katsulynx
    in main add-on
    "class Dark_PostRating_Model extends XenForo_Model"
    it's not using XFCP system to extend. is that the problem?
     
  5. Nobita.Kun

    Nobita.Kun Well-Known Member

    You might extends to Dark_PostRating_Model rather to XenForo_Model_Post. It is difference model for difference works.
     
    Hugilore111 likes this.
  6. Snog

    Snog Well-Known Member

    When a class extends a main XF class, in this case XenForo_Model, it is it's own class and you would extend it. If it's using XFCP, then you would normally extend the XF class and not the add-on's class. There may be exceptions to that.
     
    Earl likes this.

Share This Page