We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3493
    • 66 Posts
    Hi everybody,

    I’m integrating Invision Power Board to my MODx-site by using IPBWI, a very useful and handy library to perform IPB-actions outside its own environment.

    I use
    require_once('ipb/ipbwi/ipbwi/ipbwi.inc.php');
    to integrate the library in two different snippets. However, when I try to run both snippets in one document, these errors shows up:
    Fatal error: Call to a member function isLoggedIn() on a non-object in manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 4

    It doesn’t make any sense, because the same member function is used in both snippets, and works fine if I leave out the second snippet call. It doesn’t matter if I use a different and unique function either, it appears with the same error (though with a different function name).

    Snippet no. 1 - used to initiate IPBWI and show the appropriate user box:
    <?php
    require_once('ipb/ipbwi/ipbwi/ipbwi.inc.php');
    
    if($ipbwi->member->isLoggedIn())
    {
    	$user = $ipbwi->member->info();
    	
    	$modx->setPlaceholder('userName', $user["members_display_name"]);
    	
    	 if($ipbwi->group->isInGroup(array(4,20,21,22)))
    	 {
    		return $modx->getChunk('userbox2');
    	}
    	else
    	{
    		return $modx->getChunk('userbox1');
    	}
    }
    else
    {
    	return $modx->getChunk('userbox0');
    }
    ?>


    Here’s the second snippet (I’ll make the code more MODx-friendly after I make it work!):
    <?php
    
    	// Initialization
     require_once('ipb/ipbwi/ipbwi/ipbwi.inc.php');
    
    	if(isset($_POST['new_topic'])){
    		// create a new topic
    		if($ipbwi->topic->create(168, $_POST['topic_title'], $_POST['topic_desc'], $_POST['topic_post'])){
    			$ipbwi->addSystemMessage('Success', '<strong>'.$_POST['topic_title'].'</strong> successful created.');
    		}
    	}
    
    	if($ipbwi->member->isLoggedIn()){ ?>
    		<h2>Add a Topic to</h2>
    		<form action="[(~id~)]" method="post">
    			<p>Create topic with title <input type="text" name="topic_title" /></p>
    			<p>and description: <input type="text" name="topic_desc" /></p>
    			<p>in forum <strong><?php echo $forumName; ?></strong> (<a href="topic_list.php">list forum topics</a>)</p>
    			<p><textarea name="topic_post" style="width:400px;height:150px;"></textarea></p>
    			<p><input type="submit" name="new_topic" value="Create new Topic!" /></p>
    		</form>
    <?php }else{ ?>
    		<p>Please login to add a topic.</p>
    <?php }
    ?>


    Thanks, I appreciate all your help smiley
      • 10487 MODX Staff
      • 1,535 Posts
      Try using require, rather than require_once - I suspect the include file is getting included in the first snippet, but not the second.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 9130
        • 171 Posts
        This has to do with variable scoping. If you want to share the same instance of $ipbwi between the two snippets you will have to make it a global variable.
        Try adding
        global $ipbwi;

        to the beginning of both snippets (before the include).
          • 3493
          • 66 Posts
          This community is half of the reason for why MODx is such a great product. If there’s something that just doesn’t "click", the community members are always supportive and with you through the troubleshooting process.

          Your solution fixed the problem, etal. Thank you so much!
            • 25663 MODX Staff
            • 12,272 Posts
            I think the community is way more than half.
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me