?
This document uses PHP Chinese website manual Release
此案例研究演示了如何構(gòu)建一個(gè)完整的 <AppML> 互聯(lián)網(wǎng)應(yīng)用程序,具有針對(duì)數(shù)據(jù)庫中的若干表進(jìn)行信息列舉、編輯和搜索的功能。
在本章中,我們將為數(shù)據(jù)庫中的 Customers 表建立一個(gè)完整的應(yīng)用程序模型。
如需允許過濾 <AppML> 數(shù)據(jù),只需簡(jiǎn)單地向模型添加一個(gè) <filters> 元素:
<filters><query> <field label="Customer">CustomerName</field> <field>City</field> <field>Country</field></query> <order> <field label="Customer">CustomerName</field> <field>City</field> <field>Country</field></order> </filters>
如需全面了解,請(qǐng)參閱 <AppML> 參考手冊(cè)。
如需允許更新 <AppML> 數(shù)據(jù),只需簡(jiǎn)單地向模型添加一個(gè) <update> 元素:
<update> <item><name>LastName</name></item> <item><name>FirstName</name></item> <item><name>BirthDate</name></item> <item><name>Photo</name></item> <item><name>Notes</name></item> </update>
且向 <database> 元素添加一個(gè) <maintable> 和 <keyfield> 元素:
<maintable>Customers</maintable><keyfield>CustomerID</keyfield>
如需全面了解,請(qǐng)參閱 <AppML> 參考手冊(cè)。
您可以通過向 <AppML> 標(biāo)簽添加一個(gè) security 屬性來很容易地為 <AppML> 模型添加安全。
<appml security="admin">
在上面的實(shí)例中,只有用戶登錄成為用戶組 "admin" 的會(huì)員才能訪問模型。
如需為 <update> 元素設(shè)置安全,只需簡(jiǎn)單地向 <update> 元素添加一個(gè) security 屬性:
<update security="admin"> <item><name>LastName</name></item> <item><name>FirstName</name></item> <item><name>BirthDate</name></item> <item><name>Photo</name></item> <item><name>Notes</name></item> </update>
在本章中,我們將為數(shù)據(jù)庫中的每個(gè)表設(shè)立一個(gè)應(yīng)用程序模型。
創(chuàng)建一個(gè)名為 Models 的新文件夾。在 Models 文件夾中,為每個(gè)應(yīng)用程序創(chuàng)建一個(gè)模型。
<appml security=""><datasource><database> <connection>Demo</connection> <maintable>Customers</maintable> <keyfield>CustomerID</keyfield> <sql>SELECT * FROM Customers</sql> <orderby>CustomerName,City,Country</orderby></database></datasource><filters><query> <field label="Customer">CustomerName</field> <field>City</field> <field>Country</field></query><order> <field label="Customer">CustomerName</field> <field>City</field> <field>Country</field></order></filters><update security="admin"> <item><name>CustomerName</name></item> <item><name>ContactName</name></item> <item><name>Address</name></item> <item><name>PostalCode</name></item> <item><name>City</name></item> <item><name>Country</name></item></update></appml>
創(chuàng)建一個(gè)模型視圖,把它保存為 Demo_Model.html,并嘗試一下:
<h1>Customers</h1><div id="List01"></div><script src="appml.js"></script> <script>customers=new AppML("appml.htmlx","Models/Customers");customers.run("List01");</script>
然后,通過少量 JavaScript 編碼,為所有模型創(chuàng)建一個(gè)測(cè)試頁面:
<!DOCTYPE html><html><head><link rel="stylesheet" href="appml.css" /></head><body><h1>Demo Applications</h1><button onclick='myOpen("Customers")'>Customers</button><button onclick='myOpen("Products")'>Products</button><button onclick='myOpen("Suppliers")'>Suppliers</button><button onclick='myOpen("Shippers")'>Shippers</button><button onclick='myOpen("Categories")'>Categories</button><button onclick='myOpen("Employees")'>Employees</button><button onclick='myOpen("Orders")'>Orders</button><button onclick='myOpen("OrderDetails")'>OrderDetails</button><br><br><div id="Place01"></div><script src="appml.js"></script> <script>function myOpen(pname){var app_objapp_obj=new AppML("appml.php","Models/" + pname);app_obj.run("Place01");} </script></body></html>