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

Q&A for 'Creating an Addon.' by Lawrence

Discussion in 'XenForo Development Discussions' started by dmnkhhn, Oct 7, 2010.

  1. dmnkhhn

    dmnkhhn Active Member

    Lawrence, you are doing great work with your 'Creating an Addon' walkthrough.
    I thought it would be good idea to have a place where users can ask questions about your code. :)

    Please let me start with my first question:

    In LimitSig -> ControllerPublic -> LimitSig.php you are creating a new function that has the same name as the original function.
    The original function then gets overwritten by that new function but that means that we need to duplicate the original function first and copy it to LimitSig.php so that we don't loose the logic that is needed by the account. Without copying the existing code the function would not be complete.

    What happens if we have two different add-ons that both replace the actionSignatur function?

    Take this as an example:

    Original:

    PHP:
        public function actionSignature()     {
     
    $test $this->getSomeStrangeVariable();
            return 
    $test;
        }

    Addon 1:
    PHP:
        public function actionSignature()     {
     
    $test $this->getSomeStrangeVariable();
            return 
    strtoupper($test);
        }

    Addon 2:
    PHP:
        public function actionSignature()     {
     
    $test $this->getSomeStrangeVariable();
            return 
    md5($test);
        }
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    You are able to do this:

    PHP:
    public function actionSignature()
    {
          
    // Your Logic.
          
    parent::actionSignature();
          return 
    'something';
    }
    Without duplicating and/or losing functionality.
     
    MYstIC G likes this.
  3. dmnkhhn

    dmnkhhn Active Member

    Oh thanks, I totally forgot about the parent:: :D
     
  4. Lawrence

    Lawrence Well-Known Member

    When the guide is finished I'll be opening it up for discussion.

    Thanks for starting this thread, :)

    All we are adding is another check to see if a member can edit their signature, or not, with the function. If they can, show the editor, and if they cannot, spit out the error. The original actionSignature function is just a permission check that does the same thing, so any other Add-on that uses the function will be giving the same functionality as this Add-on does anyways.
     
  5. dmnkhhn

    dmnkhhn Active Member

    Something I've learned today from a co-worker and that's worth mentioning. :)

    If the parent function contains a return, you can use that return value like so:
    PHP:
    $oldReturn parent::actionSignature();
     
  6. Lawrence

    Lawrence Well-Known Member

    Sorry for the delay, I needed to be away for this week, so I'm only on and off. I am working on the next part, however; and hopefully will have it up soon.
     

Share This Page