Antidot PHP API  version 0.16.0
##PHP API to simplify integration of Antidot components
 All Classes Files Functions Variables Groups Pages
Lightweight integration example with PHP template engine

Table of Contents

Prerequisites

In order to test this example, some components are required. Details are provided in following link: Prerequisites for integration examples with PHP template engine

Set up example step by step

Most of the few steps to set up this example are detailed in AFS search API.

Here focus is given on missing steps in order to make the example fully functional.

Initialization

It should be the first step. Antidot PHP API should be loaded from PHP example script. It is not necessary to load each PHP script as one main script does it for you:

require_once "PHP_API/afs_lib.php";

Then Twig should also be loaded and initialized. Depending on your installation choices, following example may be modified to reflect your installation paths:

// You shoud addapt following paths
require_once "/var/www/php-example/Twig-1.15.0/lib/Twig/Autoloader.php";
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('/var/www/php-example/templates');
$twig = new Twig_Environment($loader, array('debug' => true));
$twig->addExtension(new Twig_Extension_Debug());

Generate HTML page

This is the last step.
Main Twig template is loaded with appropriate parameters and then rendered:

$template = $twig->loadTemplate('meta_template.html');
echo $template->render($reply);

This code brevity is obtained thanks to special array formatting of reply helpers (see AfsHelperFormat::ARRAYS).

Full example

The full example is also available here: full_lightweight_example.php

PHP template examples

Necessary templates are detailled in following link: PHP templates in details

Example conclusion

Provided example is composed of about 10 lines of PHP code. About half of these lines are related to Twig template engine. So in few PHP code lines and some PHP templates, you can get a fully functional Web interface for your Antidot search service.

Go further

Modify this example and templates then test on your own service!