• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

The Simplicity of Bridging in XenForo 2

This entry is part of a series of entries "XenForo 2 Add-On Development"
brooklyn-bridge.png

In XF1, several lines were required to bridge. In XF2, only four lines are required.

Create a file named connectXenForo2.php and add the following contents.

PHP:
<?php

  /** @var  $fileDir */
  $fileDir = '/Users/layneheiny/Documents/Sites/xf2';
  require($fileDir . '/src/XF.php');

  XF::start($fileDir);
  $app = XF::setupApp('XF\Pub\App');

Now create a file named user.php

PHP:
<?php

require_once '../connectXenForo2.php';
require_once '../connectDump.php';

$finder = \XF::finder('XF:User');
$user = $finder->where('user_id', 1)->fetchOne();

dd($user);

And the array is returned. BEAUTIFUL.

PS. My connectDump.php

PHP:
<?php

/**
 * Filename: connectDump.php
 *
 * Return information about a variable.
 * Include this file to the top of phptest files.
 *
 * Usage: dd($nameOfVariable);
 */

function dd($variable) {

  if ( is_array( $variable ) ) {

    echo '<pre>';
    print_r($variable);
    echo '</pre>';

    return true;
  }

  return var_dump($variable);
}

// End connectDump.php
  • Like
Reactions: Gracie

Blog entry information

Author
LPH
Views
2,891
Last update

More entries in General

More entries from LPH

Top