Toggle navigation

<AppML>案例研究 - 应用程序模型


此案例研究演示了如何构建一个完整的 <AppML> 互联网应用程序,具有针对数据库中的若干表进行信息列举、编辑和搜索的功能。


应用程序模型

在本章中,我们将为数据库中的 Customers 表建立一个完整的应用程序模型。


<AppML> 过滤器

如需允许过滤 <AppML> 数据,只需简单地向模型添加一个 <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>

如需全面了解,请参阅 <AppML> 参考手册


<AppML> 更新

如需允许更新 <AppML> 数据,只需简单地向模型添加一个 <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> 元素添加一个 <maintable> 和 <keyfield> 元素:

实例:

<maintable>Customers</maintable><keyfield>CustomerID</keyfield>

如需全面了解,请参阅 <AppML> 参考手册


<AppML> 安全

您可以通过向 <AppML> 标签添加一个 security 属性来很容易地为 <AppML> 模型添加安全。

实例:

<appml 
	security="admin">

在上面的实例中,只有用户登录成为用户组 "admin" 的会员才能访问模型。

如需为 <update> 元素设置安全,只需简单地向 <update> 元素添加一个 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>


完整的 Customers 模型

在本章中,我们将为数据库中的每个表设立一个应用程序模型。

创建一个名为 Models 的新文件夹。在 Models 文件夹中,为每个应用程序创建一个模型。

模型:Customers.xml

<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>



模型视图

创建一个模型视图,把它保存为 Demo_Model.html,并试一试:

视图:Demo_Model.htm

<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 编码,为所有模型创建一个测试页面:

Demo_Model_Views.htm

<!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>
显示结果 »