Error - Last Post

swoods227

New member
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
}
}
?>
 
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?
 
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
 
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?
 
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.
 
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);
 
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.
 
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.
 
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
 
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;
 
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.
 
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 :)
 
Yes, it's an add-on. I found it on the xenFORO forum and it looked like it was going to be a simple solutions to what I'm trying to accomplish. I am not a programmer by any stretch of the imagination. Here is the entire .zip file.
 

Attachments

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

Top Bottom