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

Error - Last Post

#1
Can anyone tell me what's wrong with this .php? I receive an error upon re-loading the page (line 13)

<?php
class LatestThread_Controller_Public extends XFCP_LatestThread_Controller_Public
{
public function actionIndex()
{
$response = parent::actionIndex();

if ($response instanceof XenForo_ControllerResponse_View)
{
$LatestThread = LatestThread_Model_TLatestThread::LatestThreadArray();
}

$response->params += array('LatestThread' => $LatestThread);
return $response; ERROR ON THIS LINE
}
}
?>
 

Chris D

XenForo developer
Staff member
#2
Well, what's the error?

Is it an undefined variable error?

If so, placing something like $latestThread = ''; just above the if ($response instanceof line might solve the issue.

It's hard to say without knowing what error is being thrown.

EDIT: Is this correct?

LatestThread_Model_TLatestThread

TLatestThread?
 
#4
This is the exact error:

Fatal error: Unsupported operand types in /home/content/77/11871177/html/forum/upload/library/LatestThread/Controller/Public.php on line 13
 

Liam W

Well-known member
#5
This is the exact error:

Fatal error: Unsupported operand types in /home/content/77/11871177/html/forum/upload/library/LatestThread/Controller/Public.php on line 13
I think it's referring to the line above line 13. I don't think you can use $response like that - use the main one, like this:

PHP:
<?php

class LatestThread_Controller_Public extends XFCP_LatestThread_Controller_Public
{
    public function actionIndex()
    {
        $parent = parent::actionIndex();

        $LatestThread = LatestThread_Model_TLatestThread::LatestThreadArray();
               
        $this->params += array('LatestThread' => $LatestThread);
        return $parent;
    }
}
I'm assuming your extending XenForo_ControllerResponse_View?
 
#6
Thanks. Tried that but got the same error only on line 11 this time. This is an add-on from Tenshi - Latest Thread. Just trying to find something to display the latest threads in the sidebar. Doesn't seem to be a lot of them around.
 

Chris D

XenForo developer
Staff member
#7
PHP:
$response->params += array('LatestThread' => $LatestThread);
That is line 13, not the one you highlighted.

Change it to:

PHP:
$response->params = $response->params + array('LatestThread' => $LatestThread);
 
#8
Thanks Chris, gave that a try too... same results. I guess I'm just going to have to live with the fact that this one simply doesn't work.
 

Chris D

XenForo developer
Staff member
#9
It's perhaps indicative to a situation where $response->params is not an array.

Before you return $response, try this line:

PHP:
Zend_Debug::dump($response->params);
See what that returns, if anything. It should dump some output at the top of the page.
 
#11
Tried that too..

NULL

Fatal error: Unsupported operand types in /home/content/77/11871177/html/forum/upload/library/LatestThread/Controller/Public.php on line 15
 

Chris D

XenForo developer
Staff member
#12
As I said, if $response->params is NULL and therefore not an array, you cannot do what you're trying to do.

You probably want something like:

PHP:
if (!is_array($response->params))
{
    $response->params = array();
}

$response->params += array('LatestThread' => $LatestThread);

return $response;
 
#13
Thanks Chris! That definitely got rid of the error but, apparently, the add-on isn't working. It's not displaying any "latest posts." I guess I'm going to have to search a little longer for an add-on that actually works.

I appreciate your help.
 

Chris D

XenForo developer
Staff member
#14
Let's start again for a moment...

Is this an existing add-on you're trying to get working? I thought it was an attempt to write something yourself.

If you post the full add-on code, I think I know the problem.

I'm guessing that the add-on is extending XenForo_ControllerPublic_Index which actually doesn't exist really in XenForo 1.2 in the same way. It's now used to redirect to a custom index page. Usually the forum home page.

Therefore it might be an easy fix if we see the rest of the code :)
 

Chris D

XenForo developer
Staff member
#16
Try this :)

This is the add-on you posted but fixed for XenForo 1.2.

Took quite a lot to get working and it lacks the normal polish I give to my add-ons but it works.
 

Attachments