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

$response = parent::buildLink() is missing something between the brackets

Discussion in 'XenForo Development Discussions' started by Marcus, Jul 18, 2013.

  1. Marcus

    Marcus Well-Known Member

    What could I put between buildLink( ....... ) to make it work? Thank you so much !

    PHP:
    <?php
    class VirtualForums_Route_Prefix_Threads extends XFCP_VirtualForums_Route_Prefix_Threads
    {
    public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
    {
    $response parent::buildLink();
    return 
    $response;
    }
    }
    I get a lot of errors as XenForo isn't happy about just running buildLink without any parameters.
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    You need to pass the arguments to parent.

    PHP:
    parent::buildLink($originalPrefix$outputPrefix$action$extension$data$extraParams);
     
    Last edited: Jul 18, 2013
  3. Marcus

    Marcus Well-Known Member

    I thought so, too. But XenForo is a bit picky, it doesn't like it according to its error message:

    PHP:
    <?php
    class VirtualForums_Route_Prefix_Threads extends XFCP_VirtualForums_Route_Prefix_Threads
    {
    public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
    {
    $response parent::buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams);
    return 
    $response;
    }
    }
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Yeah the correct syntax would be:

    PHP:
    parent::buildLink($originalPrefix$outputPrefix$action$extension$data$extraParams);
     
    Marcus and Jeremy like this.
  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    I guess that's what I get for copy & pasting while at work...
     
    Chris D likes this.
  6. tyteen4a03

    tyteen4a03 Well-Known Member

    Hint for the newcomers: Callback signatures allows you to specify a type hint to force that argument to be a data type when you define this function. When you directly pass the arguments into a parent function make sure to remove these type hints as they're not meant to be there when calling functions.
     
    Chris D likes this.
  7. Chris D

    Chris D XenForo Developer Staff Member

    Absolutely.

    People get tripped up on the & symbol as well. Don't include that when you're calling a function as call time pass by reference is not supported.
     
    Marcus and tyteen4a03 like this.
  8. Marcus

    Marcus Well-Known Member

    The $response variable only delivers the whole link back!
    PHP:
    class VirtualForums_Route_Prefix_Threads extends XFCP_VirtualForums_Route_Prefix_Threads
    {
       public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
       {
         
    $response parent::buildLink($originalPrefix$outputPrefix$action$extension$data$extraParams);
             
    ZEND_DEBUG::dump($response);
             
    ZEND_DEBUG::dump($response->params);

         return 
    $response;
       }
    }
    results into:
    But I want to listen to its variables like I have done in a simple code edit:
    PHP:
    if(isset($data['myforumId']))
    {
    $extraParams['node_id'] = $data['myforumId'];
    }
    How can I do that, if I can not work with response->params
     
  9. Jeremy

    Jeremy XenForo Moderator Staff Member

    If all you are doing is setting an $extraParams value, why not set it before you make the call to parent::buildLink?
     
    Marcus likes this.
  10. Marcus

    Marcus Well-Known Member

    Great solution! This is perfect:
    PHP:
    class VirtualForums_Route_Prefix_Threads extends XFCP_VirtualForums_Route_Prefix_Threads
    {
       public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
       {
         if(isset(
    $data['myforumId']))
           
    $extraParams['node_id'] = $data['myforumId'];
         
         
    $response parent::buildLink($originalPrefix$outputPrefix$action$extension$data$extraParams);
         
         return 
    $response;
       }
    }
     
    Last edited: Jul 19, 2013
  11. Jeremy

    Jeremy XenForo Moderator Staff Member

    If that's all your doing you can make it even more succinct:

    PHP:
    class VirtualForums_Route_Prefix_Threads extends XFCP_VirtualForums_Route_Prefix_Threads
    {
       public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
       {
         if(isset(
    $data['myforumId']))
           
    $extraParams['node_id'] = $data['myforumId'];
       
         return 
    parent::buildLink($originalPrefix$outputPrefix$action$extension$data$extraParams);
       }
    }
    (Sorry, I do this at work and its a general rule we follow to not set variables if they aren't used in multiple places; your code will work find if that's how you want to code it)
     
    Marcus likes this.
  12. Marcus

    Marcus Well-Known Member

    we have the same code now :) I just changed my post a minute before.
     

Share This Page