AppML Reference


Example

{
"security": "admin",
"database": {
    "connection": "mysql",
    "sql"       : "SELECT * FROM Customers",
    "orderby"   : "CustomerName"}
}

AppML Model Properties

Element Description
"data" Defines a flat file source for the model
"database" Defines a database source for the model
"filteritems" Defines filter restrictions
"rowsperpage" Defines number of rows to be fetched per page
"security" Defines the security for the model
"sortitems" Defines sorting restrictions

The "database" Property

The "database" property defines a database as the data source. It has the following sub properties:

Element Description
"connection" The name of a database connection
"execute" Array of SQL statements to be executed before data retrieval (optional)
"keyfield" The key field for the main table (optional)
"maintable" The main table for this application (optional)
"orderby" A fixed SQL orderby clause for the application (optional)
"sql" The SQL statement for retrieving data

The "data" Property

The "database" property defines a data file as the data source. It has the following sub properties:

Element Description
"type" The type of data file ("csvfile" or "xmlfile")
"filename" The name of the file
"record" The name of the XML data node (if xmlfile)
"items" The data items

Data From a Database

This model fetches records containing Customer, City, and Country from a Customer table in an SQL database:

Example

{
"database": {
    "connection": "mysql",
    "sql"       : "SELECT CustomerName, City, Country FROM Customers",
    "orderby"   : "CustomerName"
}
}

Data From a Text File

This model fetches records containing Title, Artist, and Price (as item 1, 2, and 5) from a comma separated text file:

Model

{
"data": {
    "type"   : "csvfile",
    "filename: "cd_catalog.txt",
    "items"  : [
        {"name": "Title", "index": 1},
        {"name": "Artist","index": 2},
        {"name": "Price", "index": 5}
    ]
}
}

Try It Yourself »

Data From an XML File

This model fetches records containing Title, Artist, and Price from CD nodes in an XML file:

Model

{
"data": {
    "type"    : "xmlfile",
    "filename": "cd_catalog.xml",
    "record"  : "CD",
    "items"   : [
        {"name": "Artist", "nodename": "ARTIST"},
        {"name": "Title",  "nodename": "TITLE"},
        {"name": "Country","nodename": "COUNTRY"}
    ]
}
}

Try It Yourself »

Filter Restrictions

To allow users to filter data, you can add filter information to the model:

"filteritems" : [
    {"item" : "CustomerName", "label" : "Customer"},
    {"item" : "City"},
    {"item" : "Country"}]

Sorting Restrictions

To allow users to sort data, you can add sort information to the model:

"sortitems" : [
    {"item" : "CustomerName", "label" : "Customer"},
    {"item" : "City"},
    {"item" : "Country"}]

Update Restrictions

To allow users to update data, you can include update information in the model: 

Example

"updateItems" : [
    {"item" : "CustomerName"},
    {"item" : "Address"},
    {"item" : "PostalCode"},
    {"item" : "City"},
    {"item" : "Country"}]
Note By default, AppML will let you filter, sort, or update data, only it is specified in the model.

Database Connections

Database connections are defined in appml_config.php:

appml_config.php

<?php echo("Access Forbidden");exit();?>
{
"dateformat" : "yyyy-mm-dd",
"databases": [
    {
    "connection" : "mysql",
    "host"       : "127.0.0.1:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "googleDB",
    "host"       : "192.168.1.1:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "amazonDB",
    "host"       : "mydbinstance.amazon.com:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "azureDB",
    "host"       : "azure.cloudapp.net",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    }
]
}
Note The configuration file can contain many database connections.

Application Security

You have to be logged in as a member of the "admin" group, to access this application:

Example

{
"security": "admin",
"database": {
    "connection": "mysql",
    "sql"       : "SELECT * FROM Customers",
    "orderby"   : "CustomerName"}
}

Creating Databases

Since AppML allows you to execute SQL statements before the application is started, you can use this to create a database if needed:

Model

{
"database" : {
"connection" : "myCDs",
"execute" : [
"DROP TABLE IF EXISTS CD_Catalog",
"CREATE TABLE IF NOT EXISTS CD_Catalog (CDID INT NOT NULL AUTO_INCREMENT,PRIMARY KEY (CDID),Title NVARCHAR(255),Artist NVARCHAR(255),Country NVARCHAR(255),Price NUMBER)"
]
}}

Perfect for rapid prototyping!


Private Models

You can add your own private data to the model.

This example suggests restrictions to data::

Example:

"restrictions" : [
    "fname" : {"maxlength": 40},
    "price" : {"max": 999,"min": 100}]
}

Model data can be used by server applications, and by your AppML controller.

This example uses model data to validate input:

Example:

function myController($appml) {
    if ($appml.message == "submit") {
        var price = document.getElementById("price").value;
        if (price < $appml.model.restrictions.price.min) {
            $appml.displayError(15, "Price too low!");
            return;
        }
}

AppML Attributes

Attribute Description
appml-controller Defines an AppML controller
appml-data Defines the data source for the application data
appml-include-html Defines HTML to be included
appml-repeat Defines an HTML element to be repeated


SHARE THIS PAGE

COLOR PICKER

colorpicker





Search w3schools.com:

Translate w3schools.com: