1.ThinkPHP框架的导包和加载技术
2.业界新闻页面实现过程
循环输出二位数组的标签,此标签包含两个参数,name指定控制器中传递进来的模板变量,id指定模板变量中的临时变量。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>Bootstrap 101 Template</title>
</head>
<body>
<div id="content">
<volist name="list" id="change">
<table class='table_1'>
<tr align="left" width="100px">
<td>新闻标题:</td>
<td align="left" width="500px;">
<a href="__URL__/lord/id/{$change.id}">
{$change.title}
</a>
(单击标题查看详情)
</td>
<td>
发布时间:
</td>
<td>
{$change.date_time}
</td>
</tr>
</table>
<table class="table_2">
<tr>
<td colspan="4">
<!-- 截取子字符串 -->
{$change.content|msubstr=0,5,'utf-8'}...
</td>
</tr>
</table>
<table class="table_3">
<tr>
<td width="100px">
更新时间:
</td>
<td>
{$change.update_time}
</td>
</tr>
</table>
<div class="br"></div>
</volist>
<div class="page"><span>{$page}</span></div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
</body>
</html>
控制器中news方法代码如下:
public function news(){
$News = D('News'); // 实例化模型类
$count = $News->count(); // 查询总记录数
$Page = new \Think\Page($count,3); // 实例化分页类,传入总记录数和每页显示的记录数
$show = $Page->show(); // 分页显示输出
// 进行分页数据查询,注意limit方法的参数要使用Page类的属性
$list = $News->limit($Page->firstRow.','.$Page->listRows)->select();
print_r($list);
$this->assign('list',$list); // 赋值数据集
$this->assign('page',$show); // 赋值分页输出
$this->display();
}
common/function.php关键代码如下:
<?php
function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
{
if(function_exists("mb_substr")){
if($suffix)
return mb_substr($str, $start, $length, $charset)."...";
else
return mb_substr($str, $start, $length, $charset);
}
elseif(function_exists('iconv_substr')) {
if($suffix)
return iconv_substr($str,$start,$length,$charset)."...";
else
return iconv_substr($str,$start,$length,$charset);
}
$re['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef]
[x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
$re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
$re['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/";
$re['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("",array_slice($match[0], $start, $length));
if($suffix) return $slice."…";
return $slice;
}
?>