网站租用的linux虚拟主机,经过权衡选用php开发。
有实际编程经验(c,C++基础)的很容就会学会php,非常容易入门。
网站的域名www.chshsl.com
刚开始学习的时候,网上说smarty模板引擎非常著名而且功能强大——掉入陷阱了(遇到问题后无法解决最后抛弃smarty)。
实现查询留言的功能
客户端:
使用jQuery 1.8.3,使用ajax刷新部分视图类似ASP.NET MVC部分视图
$("#viewLeaveWord").on("click",function(){
$.ajax({
url:'viewleaveword.php',
type:"GET",
cache:false,
global:false,
success:function(data, textStatus, jqXHR){
$("#view_content").html(data);
},
error:function(jqXHR, textStatus, errorThrown){
alert(jqXHR.responseText);
}
});
});
服务器端
1.先说说Smarty模板引擎的使用
viewleaveword.php
require_once(WEB_Tpl_Engine . '/Smarty.class.php');
$tpl = new Smarty();
$tpl->debugging = false;
$tpl->template_dir = WEB_Tpl_Path;
$tpl->compile_dir = WEB_Tpl_Engine . '/template_c';
$tpl->config_dir = WEB_Tpl_Engine . '/configs';
$tpl->cache_dir = WEB_Tpl_Engine . '/cache';
$tpl->caching = false;
$tpl->cache_lifetime = 0;
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
$tpl->assign('web_url',WEB_URL);
$tpl->assign('web_templetsurl',WEB_URL . '/templets');
$tpl->display('viewleaveword.html');
viewleaveword.html
<link href="<{$web_templetsurl}>/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="<{$web_templetsurl}>/js/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#ajaxAuthority").dataTable({
"bServerSide":true,
"bPaginate":true,
"bSort": false,
"bInfo":false,
"sServerMethod": "GET",
"bFilter":false,
"bProcessing": true,
"iDisplayLength":25,
"sAjaxSource": "getleaveword.php",
"aoColumns":[
{"mData":"ID","sClass":"center"},
{"mData":"Title","sClass":"center"},
{"mData":"Content","sClass":"center"},
{"mData":"L_Name","sClass":"center"},
{"mData":"Contact","sClass":"center"},
{"mData":"L_Datetime","sClass":"center"}
]
});
});
</script>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="ajaxAuthority">
<thead>
<tr>
<th>编号</th>
<th>标题</th>
<th>内容</th>
<th>留言人姓名</th>
<th>联系方式</th>
<th>留言日期</th>
</tr>
</thead>
<tbody></tbody>
</table>
使用过程中遇到的问题
引入jquery.js失败,引入js文件或者css文件时必须域名+路径。不能单独使用路径。
<link href="<{$web_templetsurl}>/css/jquery.dataTables.css" rel="stylesheet" type="text/css" /> // <{$web_templetsurl}>的值为 http://www.chshsl.com/templets
<link href="./css/jquery.dataTables.css" rel="stylesheet" type="text/css" /> //引入失败css文件不起作用。js同理
下面的问题是最大的,始终没有解决最后抛弃模板引擎
开发的时候显示的效果都是ok,没有任何问题。但是部署到linux apach上的时候发现在firefox opera浏览器没有问题。但是在IE内核上的浏览器上都显示在最左侧上始终无法让他居中。网上的说法都试过。网上说的明明成功,但是我的失败。我的虚拟主机是西部数码(www.west263.net)不知道为啥,有解决的请赐教。
最后使用纯php
viewleaveword.php
<link href="./css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="./js/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#ajaxAuthority").dataTable({
"bServerSide":true,
"bPaginate":true,
"bSort": false,
"bInfo":false,
"sServerMethod": "GET",
"bFilter":false,
"bProcessing": true,
"iDisplayLength":25,
"sAjaxSource": "getleaveword.php",
"aoColumns":[
{"mData":"ID","sClass":"center"},
{"mData":"Title","sClass":"center"},
{"mData":"Content","sClass":"center"},
{"mData":"L_Name","sClass":"center"},
{"mData":"Contact","sClass":"center"},
{"mData":"L_Datetime","sClass":"center"}
]
});
});
</script>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="ajaxAuthority">
<thead>
<tr>
<th>编号</th>
<th>标题</th>
<th>内容</th>
<th>留言人姓名</th>
<th>联系方式</th>
<th>留言日期</th>
</tr>
</thead>
<tbody></tbody>
</table>
getleaveword.php
<?php
require('lib/include/common.php');
require(WEB_CLASS . '/mysqldb.php');
require(WEB_DATA . '/leavemessage.php');
$iDisplayStart = 0;
$iDisplayLength = 10;
$iTotal = 0;
$sEcho = 1;
if(isset($_GET['iDisplayStart'])){
$iDisplayStart = intval($_GET['iDisplayStart']);
}
if(isset($_GET['iDisplayLength'])){
$iDisplayLength = intval($_GET['iDisplayLength']);
}
if(isset($_GET['sEcho'])){
$sEcho = intval($_GET['sEcho']);
}
$output = array(
"sEcho" => $sEcho,
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iTotal,
"aaData" => array()
);
try
{
$lm = new leavemessage();
$aaData = $lm->getList($iDisplayLength, $iDisplayStart, $iTotal);
foreach($aaData as $row){
$output['aaData'][] = $row;
}
$output['iTotalRecords'] = $iTotal;
$output['iTotalDisplayRecords'] = $iTotal;
unset($lm);
}catch(Exception $e){
}
echo json_encode($output);
?>
分页使用jQuery插件 jquery.pagination.js实现分页