Version: v0.6.1 - Beta.  We welcome contributors & feedback.  THanks!

PHP Interface

Overview 

There are two ways to interface with PHP.

THT to PHP 

THT has basic support for calling PHP libraries via the Php module.

Accessible PHP files should be located in app/misc/php.

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

// Load 'app/misc/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();

PHP to THT (Sideloading) 

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

NOTEWe recommend this only as a temporary solution while migrating a PHP app to THT.

First, create a new THT app as normal.

Then you can include THT modules and pages directly.

// Require the THT runtime
$pathToThtApp = 'path/to/yourapp';
require_once($pathToThtApp . '/app/.tht/main/Tht.php');

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

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

See Also