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

Error - Last Post

Discussion in 'XenForo Development Discussions' started by swoods227, Oct 6, 2013.

  1. swoods227

    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
    }
    }
    ?>
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    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?
     
  3. Liam W

    Liam W Well-Known Member

    What is the error?

    Also, indent your code and use the PHP bbcodes...
     
  4. swoods227

    swoods227 New Member

    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
     
  5. Liam W

    Liam W Well-Known Member

    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. swoods227

    swoods227 New Member

    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.
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    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. swoods227

    swoods227 New Member

    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.
     
  9. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
  10. Nobita.Kun

    Nobita.Kun Well-Known Member

    Try that:
    PHP:
    $response->params['LatestThread'] = $LatestThread;
     
  11. swoods227

    swoods227 New Member

    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
     
  12. Chris D

    Chris D XenForo Developer Staff Member

    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. swoods227

    swoods227 New Member

    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.
     
  14. Chris D

    Chris D XenForo Developer Staff Member

    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 :)
     
  15. swoods227

    swoods227 New Member

    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.
     

    Attached Files:

  16. Chris D

    Chris D XenForo Developer Staff Member

    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.
     

    Attached Files:

  17. swoods227

    swoods227 New Member

    You are AWESOME!!! I owe you a debt of gratitude! Someday, you'll have to show me how you did that.
     
  18. Brogan

    Brogan XenForo Moderator Staff Member

    He could show you but then he'd have to kill you.
     
    Chris D and Amaury like this.
  19. Amaury

    Amaury Well-Known Member

    Hm... That sounds familiar...
     
  20. swoods227

    swoods227 New Member

    Yeah, I don't think I want to know that bad. :eek:
     

Share This Page