PHP Adapter

coronium.php.run( scriptName, args_or_post_table [, http_method ] )

Executes a local PHP page and returns the results.


Parameters

scriptName

The name of the PHP file, without the extension. For example, to call a file named hello.php, you would just pass “hello”.

The php file must reside in the Coronium PHP directory.


args_or_post_table

A data table that will be used as data for POST, GET, PUT, or DELETE HTTP methods.


http_method (optional)

You can pass a specific HTTP method if needed. Defaults to “POST”


Answer

.result

Holds the PHP result as a Lua table.


.error

The error, if any. If there is no error it will be nil.


.errorCode

The error code, if any. Holds HTTP error status code.


Examples

In /php/greeting.php

<?php
  $in_data = json_decode(file_get_contents('php://input'));

  $greeting = 'Hello ' . $in_data->{"username"} . '!';

  $response = array("greeting" => $greeting);

  print(json_encode($response));
?>

In /lua/hello.lua

 local in_data = coronium.input()

 local answer = coronium.php.run( 'greeting', in_data )

 coronium.output( answer )