Lianja/VFP Server Pages

From Lianjapedia
Revision as of 06:26, 30 June 2020 by Yvonne.milne (Talk | contribs)

Jump to: navigation, search

Lianja Cloud Server has built-in support for Lianja/VFP Server Pages.

Lianja/VFP Server pages (.rsp pages) have the Lianja database and scripting engine embedded in them. You can write and test Lianja/VFP Server Pages in the Lianja App Builder and "Publish to the Cloud website" to deploy them.

In addition to the built-in commands and functions supported the Lianja/SDK C/C++ API provides the ability to write custom functions and classes in C/C++ to extend the functionality already offered. This is similar to but much simpler than using the PHP Extensions API to extend PHP.

See Also

EXECRSP(), JavaScript Server Pages

Page processing directives

Page Directive Description
<%= expression %> Evaluates and outputs expression.
<% code %> Executes code.
<%@ include=cExpression %> Includes the file specified in cExpression.
<%@ codepage=cExpression1,include=cExpression2 %> Includes the file specified in cExpression2 converted from the cExpression1 codepage (e.g. "1251") to utf-8.
<%@ codebehind=cExpression %> Executes the script file specified in cExpression.

When a Lianja/VFP Server Page is executed the following are available to the script (in addition to the complete VFP compatible cross-platform scripting language implemented in Lianja).

Global associative arrays

Array Description
_ARGS[] Contains all arguments passed to the rsp page.
_COOKIE[] Contains cookie names and values.
_FILES[] Contains information about uploaded files.
_GET[] Contains GET parameter names and values.
_POST[] Contains POST parameter names and values.
_REQUEST[] Contains all arguments passed to the rsp page.
_SERVER[] Contains server information.
_SESSION[] Contains session information.

Global objects

Response

Method Description
addCookie(name, value) Adds the specified cookie to the cookies that will be sent back to the browser.
addHeader(name, value) Adds a custom HTTP response header to the response headers which will be sent back to the browser.
appendToLog( message ) Writes a message to the end of the system log.
authenticate( [message] ) Causes the browser to prompt for username/password with optional message.
clear() Clears the response output buffer.
flush() Flushes out the buffers and sends data to the browser.
include( filename ) Includes the contents of filename into the output data that will be sent back to the browser.
redirect( url ) Redirects to the specified url.
write( text ) Writes text into the output stream that will be sent back to the browser.
writeFile( filename ) Writes out the contents of filename into the output stream that will be sent back to the browser.
isLoggedIn() Returns true if user is logged in.

Built-in commands/functions

Command/Function Description
? cExpression Evaluates and outputs the result of cExpression into the output stream.
base64_encode_image(object_fieldname [,width,height [,cssattr ]]) Generates the base64 encoded contents of an object field image as an IMG tag with the specified dimensions and outputs into the output stream. cssattr can be used to add additional CSS attributes onto the IMG tag e.g. "class='myclass'".
die(message) Terminates the request and returns a custom message which will be displayed in the browser.
echo cExpression Evaluates and outputs the specified cExpression into the output stream.
getParameter(param, defaultvalue) Returns a named parameter from the request.
getUrl( url [, timeout [, headers, [,filename]]] ) Fetch the contents of the specified url and return the result of the HTTP GET as a string or if the optional filename is specified into that file. If JSON data is returned you can use json_decode() on the result and them access the JSON objects in VFP-style scripting syntax.
include( filename ) Includes the file contents specified by filename at this point in the script.
json_encode( oVar ) Encodes the object oVar in JSON format.
json_decode( cExpr ) Decodes the specified JSON string which is the result of the expression cExpr as an object.
json_decode_file( filename ) Decodes the JSON in the specified file designated by filename as an object.
move_uploaded_file(fromfilename, tofilename) Moves the uploaded file fromfilename to the location specified in tofilename.
odata_Create( url, jsondatastring ) Inserts a new record described by the specified OData url whose field names and values are in the specified JSON encoded string e.g. '{"name":"smith", "salary":1000}'
odata_Delete( url, jsondatastring ) Deletes the record described by the specified OData url whose field names and values are in the specified JSON encoded string e.g. '{"name":"smith"}'
odata_Read( url [, filename] ) Queries data based on the specified OData url and sends the JSON encoded data back to the browser. If filename is specified the JSON data is saved into the specified file.
odata_Update( url, jsondatastring ) Updates a record described by the specified OData url with field names and values as specified by the JSON encoded string e.g. '{"name":"smith", "salary":1000}'
postUrl( url [, timeout [, headers, [,filename]]] ) Posts the specified url using a HTTP POST request. Send the contents of the optional file if filename is a valid filename or send it as the data in the POST request.
include_once( cExpression ) Loads the library specified in cExpression only once.
All of the VFP commands and functions supported by Lianja All non-UI VFP commands and functions supported by Lianja can be used in Lianja/VFP Server Pages. This includes the NoSQL navigational commands and the SQL commands.

Lianja.writeOutput() and Lianja.console()

From v5.3 the Lianja.writeOutput() and Lianja.console() Lianja system object methods can be used in server-side Lianja Server Pages in Web Apps to assist in debugging. The output is sent to the current debug_server_xxx.txt file in the Lianja debug directory.

View an example Lianja/VFP Server Page. Further examples are included in the Lianja Cloud Server distribution in the C:\lianja\cloudserver\tenants\public\wwwroot\examples folder (Windows) and /opt/lianja/cloudserver/tenants/public/wwwroot/examples directory (Linux) and in the Lianja App Builder demo Apps and Library.