Please upgrade here. These earlier versions are no longer being updated and have security issues.

How do I display the latest comment per discussion on the front page?

edited September 2009 in Vanilla 2.0 - 2.8
I tried adding:

$Comment = $this->Context->ObjectFactory->NewContextObject($this->Context, 'Comment');

echo $Comment->Body;

within the loop of the file vanilla/themes/MyTheme/discussion.php, but I am getting all sorts of errors.

Any suggestions on how to display the latest comment per discussion thread?

Thanks!

Comments

  • I am also trying:

    $sql = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
    $sql->SetMainTable('LUM_Comment','LUM_Comment');
    $sql->AddSelect('Body', 'LUM_Comment','"Body"');
    $sql->AddWhere('LUM_Comment','DiscussionID','DiscussionID',10000,'=');
    $result = $this->Context->Database->Select($sql, 'SenderObject', 'SenderMethod' , 'An error occurred while fetching body field.');
    $fr = $result->FirstRow();
    var_dump($fr);
    But this is displaying the error:
    Notice: Undefined index: LUM_Comment in /var/www/vhosts/default/htdocs/vanilla/library/Framework/Framework.Functions.php on line 601 Notice: Undefined index: LUM_Comment in /var/www/vhosts/default/htdocs/vanilla/library/Framework/Framework.Class.SqlBuilder.php on line 357 Notice: Undefined index: LUM_Comment in /var/www/vhosts/default/htdocs/vanilla/library/Framework/Framework.Class.SqlBuilder.php on line 600 Notice: Undefined index: DiscussionID in /var/www/vhosts/default/htdocs/vanilla/library/Framework/Framework.Class.SqlBuilder.php on line 601 Notice: Undefined index: in /var/www/vhosts/default/htdocs/vanilla/library/Framework/Framework.Class.SqlBuilder.php on line 601
    A fatal, non-recoverable error has occurred
    Technical information (for support personel):

    Error Message
    An error occurred while fetching body field.
    Affected Elements
    SenderObject.SenderMethod();

    The error occurred on or near: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS "Body" FROM LUM_ LUM_Comment WHERE LUM_Comment. = 'DiscussionID.'' at line 1

    For additional support documentation, visit the Lussumo Documentation website at: lussumo.com/docs

    Any idea what the problem is here?

  • I finally figured it out:

    $sql = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
    $sql->SetMainTable('Comment', 'LUM_Comment');
    $sql->AddSelect('Body', 'LUM_Comment');
    $sql->AddWhere('LUM_Comment','DiscussionID','',$Discussion->DiscussionID,'=','');
    $sql->AddOrderBy('DateCreated','LUM_Comment','desc');
    $result = $this->Context->Database->Select($sql, 'SenderObject', 'SenderMethod' , 'An error occurred while fetching body field.');
    $row = $this->Context->Database->GetRow($result);
    var_dump($row['Body']);
    This will display the latest comment per discussion.


  • edited October 2009
    @thorie: As a vanilla-2-newbie I haven't known that you can put your php files in the theme folder and that they overwrite the original ones (I thought it's just for the css files).

    So I copied discussion.php from "applications\vanilla\views\post" to "themes\myTheme" -- modified the php, and ... nothing changed. The standard one gets loaded.

    Do I have to enable it somewhere?
  • how does this work exactly? what files need to be edited and where?
  • lucluc ✭✭
    The LUM stuff is vanilla 1.
  • I see. Thanks @luc. I searched the forum but this is the only post I found dealing with this. Any solutions for vanilla 2?
  • Anybody know how to do this?
  • @luc any help on this one?
  • Nope, sorry. Don't know enough.
Sign In or Register to comment.