Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

SqlBuilder Problem

edited April 2007 in Vanilla 1.0 Help
function MakeFileAfterNewComment($Context) { $Comment = $Context->DelegateParameters['Comment']; if($Comment->WhisperUserID == false) { // Init SqlBuilder $s = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder'); // Get the Discussion Name $DiscussionID = $Comment->DiscussionID; $s->SetMainTable('Discussion', 'd'); $s->AddSelect('Name', 'd'); $s->AddWhere('d', 'DiscussionID', '', $DiscussionID, '='); $DiscussionName = $this->Context->Database->Execute($s, $Comment, '', 'An error occurred while finding a Discussion name.'); } } $Context->AddToDelegate('CommentManager','PreSaveNewComment','MakeFileAfterNewComment');

From that i get this...

Fatal error: Call to a member function SetMainTable() on a non-object in C:\Server\htdocs\Vanilla\extensions\Flash Updator\default.php on line 21

Any help? I'm trying to learn how to use the sqlbuilder...

Comments

  • edited April 2007
    I think all the SQLbuilder code is OK, but I don't believe the context object is passed to the function directly... thus the ObjectFactory doesn't build it properly.

    Try this:function MakeFileAfterNewComment($CommentManager) { $Comment = $CommentManager->Context->DelegateParameters['Comment']; if($Comment->WhisperUserID == false) { // Init SqlBuilder $s = $CommentManager->Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder'); // ... $DiscussionName = $CommentManager->Context->Database->Execute($s, $Comment, '', 'An error occurred while finding a Discussion name.');
  • I can't even connect to the object factory through either my code or yours
  • MarkMark Vanilla Staff
    edited April 2007
    Is your code included on a page where the CommentManager is created (ie. comments.php)?

    Also, WallPhone missed one context reference. It should always be accessed through the object that was passed into the function:

    function MakeFileAfterNewComment(&$CommentManager) { $Comment = $CommentManager->Context->DelegateParameters['Comment']; if ($Comment->WhisperUserID == false) { // Init SqlBuilder $s = $CommentManager->Context->ObjectFactory->NewContextObject($CommentManager->Context, 'SqlBuilder'); // Get the Discussion Name $DiscussionID = $Comment->DiscussionID; $s->SetMainTable('Discussion', 'd'); $s->AddSelect('Name', 'd'); $s->AddWhere('d', 'DiscussionID', '', $DiscussionID, '='); $DiscussionName = $CommentManager->Context->Database->Execute($s, $Comment, '', 'An error occurred while finding a Discussion name.'); } } $Context->AddToDelegate('CommentManager','PreSaveNewComment','MakeFileAfterNewComment');
  • Notice: Undefined property: Context::$DelegateParameters in ...\Vanilla\extensions\Flash Updator\default.php on line 12 Notice: Trying to get property of non-object in ...\Vanilla\extensions\Flash Updator\default.php on line 13 Notice: Trying to get property of non-object in ...\Vanilla\extensions\Flash Updator\default.php on line 19 Catchable fatal error: Object of class SqlBuilder could not be converted to string in ...\Vanilla\library\Framework\Framework.Class.MySQL.php on line 37

    Well, that's what i get.... is something wrong here?
  • MarkMark Vanilla Staff
    edited April 2007
    Another typo... Let's try this again:

    function MakeFileAfterNewComment(&$CommentManager) { $Comment = $CommentManager->DelegateParameters['Comment']; if ($Comment->WhisperUserID == false) { // Init SqlBuilder $s = $CommentManager->Context->ObjectFactory->NewContextObject($CommentManager->Context, 'SqlBuilder'); // Get the Discussion Name $DiscussionID = $Comment->DiscussionID; $s->SetMainTable('Discussion', 'd'); $s->AddSelect('Name', 'd'); $s->AddWhere('d', 'DiscussionID', '', $DiscussionID, '='); $ResultSet = $CommentManager->Context->Database->Select($s, $Comment, '', 'An error occurred while finding a Discussion name.'); } } $Context->AddToDelegate('CommentManager','PreSaveNewComment','MakeFileAfterNewComment');
  • edited April 2007
    Thanks Mark, we hit the spot on this one :D

    This'll help me when i confront the RSS addon...
This discussion has been closed.