Version: v0.7.0 - Beta.  We welcome contributors & feedback.

PHP Interface

Overview 

There are two ways to interface with PHP.

Calling PHP from THT 

You can call PHP libraries via the Php Module.

The PHP files should be located in code/php.

They can be executed via Php.require, which uses PHP's require_once function.

// Load 'code/php/myPhpLibrary.php'
Php.require('myPhpLibrary.php')

// Call a global function
$val = Php.call('a_php_function', 'arg1', 'arg2')

// Construct a PHP object
// Namespaces can use '/' instead of '\'
$obj = Php.new('Abc/MyClass')

$obj.someMethod()

Calling THT from PHP 

If you have a pre-existing PHP app that you want to add THT pages to, you can sideload THT.

First, create a new THT app as normal.

Then you can include THT modules and pages directly.

<?php

// Require the THT runtime
$pathToThtApp = 'path/to/thtapp';
require_once($pathToThtApp . '/system/tht/lib/core/ThtSide.php');

// Include a THT module and call its functions
$testMod = Tht::module('TestModule');
$testMod->myFunction(123);

// Or run a route and then exit the script.
Tht::page('/my-route');

See Also