XenForo and CodeIgniter Integration

Background 

For a current project I am experimenting with XenForo and integrating CI (CodeIgniter) to build some extra functionality.

They are other areas of the site (not form specific). I just needed to be sure that the user (Visitor in XenForo terminology) was logged in, and if they were a super admin; while having access to libraries and the MVC of CI.



XenForo

The set up for XenForo is fairly minor, there is none. Just install it and you're done, for this example it's installed in :

/var/www/xenforo

URL being :

http://www.example.com/xenforo/



CodeIgniter

I've installed (a default 1.7.3) in a separate directory for the moment just for ease of example (structure you site as needed, as always):


/var/www/ci

Example URL being :

http://www.example.com/ci/

Browsing to, gives us the obligatory all OK from the CI welcome controller :




xF_auth

I've shared the CI libary on gitHub : https://github.com/JeremyHutchings/xF_auth

As with any CI libary, download that and put the config/xf_auth.php config file in :

/var/www/ci/system/application/config/

and the library/xf_auth.php in :

/var/www/ci/system/application/library/

The two config settings in there being the URL for the forum and the path for the XenForo install, only the file path is used at the moment, so :

$config['xfAuth']['fileDir'] = '/var/www/ci';

No harm is setting the forum URL, I've just not written the functions to use it yet.

xF_auth is a wrapper for the XenForo_Visitor class, which is part of the XenForo core. It handles getting an instance of the Visitor and checking permissions for various actions and access.



Hello World

With CI, XenForo and xF_auth all installed and configured, time to test CI.


The default welcome controller for CI is :

/var/www/ci/system/application/controllers/welcome.php

Edit this file and add the library load to the constructor :

class Welcome extends Controller 
{
    function Welcome()
    {
        parent::Controller();
        $this->load->library('xf_auth');
    }

     ...

And then for the sake of testing, echo some debug from the controller opposed to creating a new view. That can be done once you get into development.
    ...
    function index()
    {
        if($this->xf_auth->isLoggedIn())
        {
            echo "You're logged in to XenForo !" .
            "
User id :: " . $this->xf_auth->getUserId() .
            "
username :: " . $this->xf_auth->get('username') .
            "
email :: " . $this->xf_auth->get('email');
        }
        else
        {
            echo "You are not logged in";
        }

        $this->load->view('welcome_message');
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

Now you will see :


(as long as you've logged into XF that is!)

You have now bootstrapped XF in another environment and can build functionality else where on the site using familiar CI MVC techniques.


Future Development

XenForo at time of writing is in beta, and approaching RC. Though having a library abstract the bootstrapping means that any changes can be hidden from a CI application and implementation.

Usergroups - The next functions to be added will check what usergroups and permissions the user/Visitor has so the C of MVC in CI can build the views correctly.

Templates - Being able to call XF templates within CI (view integration), though using the XF context and phrasing is a goal.


@JeremyHutchings

Comments

  1. Why you use CI? why don't you write in ZendF and that's it?

    ReplyDelete
  2. Because CI is more lightweight and easier to get going with. As it happens I was working on with a different project at the time so thought I'd give it a go.

    I'm evaluating at the moment, now I've done this I'll check out Joomla's suitability for the project.

    ReplyDelete
  3. For Joomla, wait til 1.6 is released. Almost 3 years in the making.
    Joomla 1.6 RC1 was just released.
    There are unlikely to be any major changes in the RC period.

    As well, Jfusion is pretty much ready with an Authentication Engine for Joomla and other software. If you want: content, user names and passwords, avatars, etc to flow between the Joomla and xF then make sure you use jfusion.

    There is a jfusion plugin for xenforo being created .... read the xenforo forums.

    :) Digital Doctor.

    ReplyDelete
  4. 3 years ........ quite the haul.

    ReplyDelete
  5. can you say me how to get number of unreaded alerts ?

    ReplyDelete
  6. Have a look in the table :

    xf_user_alert

    ReplyDelete
  7. also be able to get forum messages .. smt like this : http://phpdave.com/MyBBIntegrator/Examples/Forums_and_Categories is mybb integrator but it has so many features

    ReplyDelete
  8. Oh yea, that will be easy. Now we're in RC I can add all kinds of other things.

    ReplyDelete
  9. p.s. if you can add and "if user is banned" option will be very usefull

    ReplyDelete
  10. You sir, are a damn genius.

    Been working with codeigniter for a few years and this will really let me hit the ground running

    ReplyDelete
  11. Registration script ( users be able to register from website not only from forum ...)


    editing upgrading password


    ..

    also get user contact info skype icq aim .. www

    ReplyDelete
  12. who is online, nr of users, guests

    ReplyDelete
  13. Make tea, make a cake yes yes ;)

    ReplyDelete
  14. On where side the logon process ?
    On CI or XF?

    ReplyDelete
  15. Can you please tell me how to integrate Xenforo Login in codeigniter?

    ReplyDelete

Post a Comment

Popular posts from this blog

How to create SugarCRM graphs

Virtual Teams and Remoting Working; a research based perspective

Burnout and how to deal with it