How to Create a Bridge?

  • Thread starter Thread starter Deleted member 15541
  • Start date Start date
I've been trying to use this class:
http://xenforo.com/community/threads/how-to-create-a-bridge.28515/#post-332676

I'm trying to log a user in using the following code:
$xenUser = appXenForo::login($email, $password);
appXenForo::setLogin($xenUser);

But I keep getting the following error:

Fatal error: Class 'XenForo_Model' not found in /home/ausfifac/public_html/inc/xenforo_functions.php on line 203

xenforo_functions.php is the appXenForo class with the additional setAvatar() function provided by JaredNZ.

The line causing the error:
$dbLoginModel = XenForo_Model::create('XenForo_Model_Login');

What would be causing this? I've set the forum directory properly and I have the Model.php file in the library/Xenforo directory.

Help would be greatly appreciated. Thanks!
hi AUSFIFA,

you can just change your code to this,
in place of directly call XenForo_Model,you can use something like this
$db = XenForo_Application::get('db');
$cUser = $db->fetchRow("SELECT * FROM xf_user WHERE `username` = '$sUsername' LIMIT 1");
 
PHP:
/*
    *Create a XenForo User:
    */
    public static function createUser($sUsername, $sEmail, $sPassword, array $aAdditionalData = array()) {
        //Create the username from the person's name:
        $sUsername = str_replace(' ', "_", $sUsername);
       
        //Set User Data
        $cWriter = XenForo_DataWriter::create('XenForo_DataWriter_User');
        $cWriter->set('username', $sUsername);
        $cWriter->set('email', $sEmail);
        $cWriter->setPassword($sPassword);
        $cWriter->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
        $cWriter->set('user_state', 'valid');
        foreach ($aAdditionalData AS $data => $key) {
        $cWriter->set($data, $key);
        }

      
        try{
            $cWriter->save();
        }catch(Exception $e){
            echo $e->getMessage();
        }
       

        $cUser = $cWriter->getMergedData();
        return $cUser['user_id'];
    }

Code bit added for handling exception in create user function.
If duplicate email is entered or less than 3 characters entered for user name, this bit will help to handle the exception.
 
Looks like I have an issue with creating the sessions to populate, any ideas what usually causes :

No entry is registered for key 'session'

?
 
Top Bottom