• 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

Marcus

Well-known member
#1
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.
 

Jeremy

Well-known member
#2
You need to pass the arguments to parent.

PHP:
parent::buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, $extraParams);
 
Last edited:

Marcus

Well-known member
#3
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
 

tyteen4a03

Well-known member
#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.
 

Marcus

Well-known member
#8
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
 

Marcus

Well-known member
#10
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:

Jeremy

Well-known member
#11
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)