'$Nickname'', ''A'')";
}
$result = $db->query($sql);
}
}
if($type != "data")
{
if ($result == "true"){
echo json_encode(array(''success''=>true));
} else {
echo json_encode(array(''msg''=>''had errors occured. '' . $result));
}
}
?>
dal 资料存取层 定义完了以后,就可以来实现 UI 介面来呼叫 dal,因为是使用 AJAX 的方式 来存取
资料,所以 MVC 中的控制层有一部分是放在 介面层中,这部分,后面可以在用 JavaScript 将这部分的控制层标准化,在藉由 php 后端来传递参数呼叫,如此一来,则还是将所有控制大权集中在一支程式中,这些后面文章会再来介绍,这边先暂时打住。
datagrid.php
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>easyUI datagrid</title>
<link rel="stylesheet" type="text/css" href="./../JS/EasyUI/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="./../JS/EasyUI/themes/icon.css">
<script type="text/javascript" src="./../JS/jquery.js"></script>
<script type="text/javascript" src="./../JS/EasyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="./../JS/EasyUI/easyui-lang-zh_CN.js"></script>
<style type="text/css">
#fm{
margin:0;
padding:10px 30px;
}
.ftitle{
font-size:14px;
font-weight:bold;
color:#666;
padding:5px 0;
margin-bottom:10px;
border-bottom:1px solid #ccc;
}
.fitem{
margin-bottom:5px;
}
.fitem label{
display:inline-block;
width:80px;
}
</style>
<script type="text/javascript">
var url;
function newUser(){
$(''#dlg'').dialog(''open'').dialog(''setTitle'',''New User'');
$(''#fm'').form(''clear'');
url = ''dal_user.php?type=add'';
}
function editUser(){
var row = $(''#myDG'').datagrid(''getSelected'');
if (row){
if(typeof(row.UNum) !== ''undefined'')
{
$(''#dlg'').dialog(''open'').dialog(''setTitle'',''Edit User'');
$(''#fm'').form(''load'',row);
url = ''dal_user.php?type=mod&id=''+row.UNum;
}else{
alert("undefined");
}
}
}
function saveUser(){
$(''#fm'').form(''submit'',{
url: url,
onSubmit: function(){
//alert(''sub :''+ url);
return $(this).form(''validate'');
},
success: function(result){
var result = eval(''(''+result+'')'');
//alert(result.success);
if (result.success){
$(''#dlg'').dialog(''close''); // close the dialog
$(''#myDG'').datagrid(''reload''); // reload the user data
} else {
$.messager.show({
title: ''Error'',
msg: result.msg
});
}
}
});
}
function removeUser(){
var row = $(''#myDG'').datagrid(''getSelected'');
if (row){
$.messager.confirm(''Confirm'',''Are you sure you want to remove this user?'',function(r){
if (r){
//alert(row.UNum);
$.post(''dal_user.php'', {type:''del'', id:row.UNum}, function(result){
if (result.success){
$(''#myDG'').datagrid(''reload''); // reload the user data
} else {
$.messager.show({ // show error message
title: ''Error'',
msg: result.msg
});
}
},''json'');
}
});
}
}
</script>
</head>
<