PHP Interface
Overview
There are two ways to interface with PHP.
- Call PHP Libraries from your THT app, using the
Php
module. - Sideload THT in a pre-existing PHP app.
Call PHP Libraries From Your THT App
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()
Sideload THT in a Pre-Existing PHP App
If you have a pre-existing PHP app, you can sideload a THT app to call the modules in it.
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');