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

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.
 
You need to pass the arguments to parent.

PHP:
parent::buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, $extraParams);
 
Last edited:
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;
}
}

Parse error: syntax error, unexpected '&', expecting '(' in ...\xenforo\library\VirtualForums\Route\Prefix\Threads.php on line 6
 
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.
 
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.
 
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:
string(13) "threads/xy.1/"
NULL
string(20) "threads/xy.1/preview"
NULL
string(13) "threads/xy.1/"
NULL
string(27) "threads/xy.1/list-item-edit"
NULL
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
 
If all you are doing is setting an $extraParams value, why not set it before you make the call to parent::buildLink?
 
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:
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)
 
Back
Top Bottom