Using Vanilla(Garden) framework withing another framework
Hello everybody.
I've just recently started embedding Vanilla forum into an existing website written on another framework. I needed Notifications to be displayed on my site's home page for every registered user. I have found an example of code I believe in Vanilla 2.1 branch of the forum which was used to enable Garden within another framework but it didn't work as described.
<?php
/*
* Include the Garden framework used by Vanilla.
*/
// Define constants like the way that Vanilla does in its index.php file.
define('APPLICATION', 'Vanilla');
define('APPLICATION_VERSION', '2.1');
define('DS', '/');
define('PATH_ROOT', './forum'); // Change PATH_ROOT to the path to your forum.
// Display all PHP errors for development purposes.
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR);
ini_set('display_errors', 'on');
ini_set('track_errors', 1);
ob_start(); // Buffer the output of the code below.
require_once(PATH_ROOT . '/bootstrap.php'); // Require the bootstrap for the framework used by Vanilla.
$Dispatcher = Gdn::Dispatcher(); // Declare an alias for the dispatcher.
// Set up the dispatcher.
$EnabledApplications = Gdn::ApplicationManager()->EnabledApplicationFolders();
$Dispatcher->EnabledApplicationFolders($EnabledApplications);
$Dispatcher->PassProperty('EnabledApplications', $EnabledApplications);
// Mimic the DiscussionsController().
$Controller = new DiscussionsController();
Gdn::Controller($Controller);
Gdn::Request()->WebRoot('');
ob_end_flush(); // Stop and send the buffer for the code above.
The whole forum home page appeared on my website's home page with bugs. So is there any way to use Vanilla code and access it's data withing another web site?
Comments
This is not a real answer to your question, but maybe you can utilize what's already there: if you are already using jsConnect, your users are authenticated and you would be able to get their notifications like that: https://vanillaforums.org/profile/notifications.json
Thanks for the reply. As far as I know notifications.json can be used only with Vanilla hosting. Its API for notifications is not available without the hosting. Am I correct?
No. For getting information, you can use those parameters:
yourforum.com/discussions/123?DeliveryMethod=JSON&DeliveryType=VIEW
To get an idea on what is possible, take a look at /conf/constants
Instead of using the parameters, you can simply append a .json after the url you like to fetch
Force loading framework is terrible for performance.
One of the most misleading term you hear is "bridge", it can mean a number of different things. There is no one thing that melds frameworks together.
R_J idea of using json(p) is a great one.
grep is your friend.
Ok, thank you, guys. I'll try.