Accessing viewParams via Parent?

James

Well-known member
I'm extending the member controller and I'm trying to modify the $user array inside the viewparams.

The simple question is: How can I access the $viewParams variable via parent::actionMember(), if at all?

To put it simply: I want to override {$user.username} to {$user.somethingelse} without physically going through the template replacing {$user.username} with {$user.somethingelse}

Hope I made it clear.
 
PHP:
$response = parent::actionMember();
$viewParams = $response->params;
?
I tried that method. Using that method, I should be able to replace {$user.username} with {$user.myString} by doing this:
PHP:
$viewParams['user']['username'] = $viewParams['user']['myString'];

But that doesn't work.
 
Mm, it should if you're doing it right. Just modifying the $viewParams variable won't work because it's not being returned to the original response.

PHP:
$response = parent::actionMember();
$viewParams = $response->params;

$viewParams['user']['username'] = $viewParams['user']['myString'];

$response->params = $viewParams;
return $response;
 
Now I'm getting a strange error when trying to access the member card:
Undefined property: XenForo_ControllerResponse_Reroute::$params on line 8. The code:

PHP:
public function actionMember()
{
$response = parent::actionMember();
$viewParams = $response->params;

if($viewParams['user']['myField'])
{
$viewParams['user']['username'] = $viewParams['user']['myField'];
}

$response->params = $viewParams;
return $response;
}

I think it's too late for me to be working :whistle:
 
The card is accessed with the member action, but it internally just redirects to actionCard(); (or something, if memory serves right). Anyways, as such, it won't have params.

Soo

PHP:
$response = parent::actionMember();

if (!isset($response->params))
{
    return $response;
}

$viewParams = $response->params;

if($viewParams['user']['myField'])
{
    $viewParams['user']['username'] = $viewParams['user']['myField'];
}

$response->params = $viewParams;
return $response;
 
I've just realised that I cannot modify any template where I have edited the viewParams via extending the relevant controllerpublic file.

Example:
PHP:
class MyAddon_ControllerPublic_Thread extends XenForo_ControllerPublic_Thread
{
public function actionIndex()
{
$response = parent::actionIndex();

foreach($response->params['posts'] AS $postId => $content)
{
if($content['myField'])
{
$response->params['posts'][$postId]['username'] = $content['myField'];
}
}

return $response;
}
}

I now can't modify any of the content inside any template that relies on XenForo_ControllerPublic_Thread, not even when I disable the add-on.

Upon trying to edit the template I get an error telling me to look at the JS console. When I do, it tells me this:
Code:
PHP Array
handleServerError()xenfor...1d5099e (line 1148)
xhr = XMLHttpRequest { responseText="Array", mozResponseArrayBuffer=ArrayBuffer, more...}
responseText = "parsererror"
errorThrown = "Invalid JSON: Array"
error()xenfor...1d5099e (line 1099)
xhr = undefined
textStatus = undefined
errorThrown = undefined
handleError()jquery....min.js (line 142)
a = Object { url="admin.php?templates/save-multiple.json", global=true, more...}
b = XMLHttpRequest { responseText="Array", mozResponseArrayBuffer=ArrayBuffer, more...}
d = "parsererror"
e = "Invalid JSON: Array"
onreadystatechange()jquery....min.js (line 141)
m = readystatechange
console.error('PHP ' + xhr.responseText);
 
Nothing else stands out? Other templates are fine? All extended ones fail?
File health check in ACP?

Haven't dug into the template system much but it looks like it's trying to make an ajax request to save multiple templates and it's returning an array unexpectedly. Are you sure you're not accidentally messing with the template engine?
 
Ah, I've found the source now it's alright. I forgot I was debugging in XenForo files :mad: I really should sleep.
 
Top Bottom