Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How do I pull a discussion from Vanilla 2 to another page?

edited April 2010 in Vanilla 2.0 - 2.8
I want to import a vanilla discussion to my apps text page, so users can read and comment. Is there any way to do this? is it through a hook? or do I need to copy vanilla app code to my app?

Comments

  • NickENickE New
    edited April 2010
    Here's an example of how you could get the first 10 discussions from an independent script. There might be a better way to do this, but it seems to work alright.
    <?php

    define('APPLICATION', 'Garden');
    define('APPLICATION_VERSION', '1.0');

    define('DS', DIRECTORY_SEPARATOR);
    define('PATH_ROOT', dirname(__FILE__) /* or wherever garden's installed */);

    require_once(PATH_ROOT.DS.'bootstrap.php');

    Gdn::Session()->Start(Gdn::Authenticator());

    include_once(PATH_APPLICATIONS.DS.'vanilla'.DS.'models'.DS.'class.vanillamodel.php');
    include_once(PATH_APPLICATIONS.DS.'vanilla'.DS.'models'.DS.'class.discussionmodel.php');

    $Discussion = new Gdn_DiscussionModel();
    $Sql = $Discussion->Get(0, 10); /* first ten discussions */

    while (($Row = $Sql->NextRow()) !== false) {
    echo '<strong>'.$Row->Name.'</strong> by '.$Row->FirstName.' ('.substr(htmlspecialchars($Row->FirstComment), 0, 20).')<br />';
    }

    ?>
    ...and with some copypasta and hacksauce you could probably get what you're after.
Sign In or Register to comment.