class MsgManageAction extends CommonAction
{
public function index(){
import(‘ORG.Util.Page‘);
//import调用的是message/ThinkPHP框架目录下的扩展包Extend/Library/ORG/Util/中的Page.class.php类文件
$count = M(‘board‘)->count();
//调用board库,取出所有数据条数
$page = new
Page($count
,10);
//实例化Page类,其中第一个参数为显示条数的总数,每次取出十条,也就是下面$page->listRows的值
$limit
= $page->firstRow . ‘,‘ .
$page->listRows;
//$page->firstRow为查找的起始条数,默认为0,如果$page->listRows为10,那么第2页的$page->firstRow就为10,以此类推
$board
= M(‘board‘)->order(‘time
DESC‘)->limit($limit)->select();
//注意,这里较之前的版本添加了->limit($limit)
$this->board
= $board;
$this->page =
$page->show();
//将$page->show()通过show方法解析$page内容显示并赋值给模板变量,供模板调用
$this->display();
}
Public function delete(){
$id = I(‘id‘,‘‘,‘intval‘);
if(M(‘board‘)->delete($id)){
$this->success(‘删除成功‘,U(‘index‘));
}else{
$this->error(‘删除失败‘);
}
}
}
ThinkPHP中页面输出的过程是读取模板文件,然后进行模板解析(也支持调用第三方模板引擎解析),但是有一些情况,我们并没有定义模板文件,或者把模板文件保存在数据库里面,那么这个时候进行页面输出的时候,我们是无法进行模板文件读取的,3.1版本则针对这样的情况增加了内容解析输出的功能。
<!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>Message Board
BackGround</title>
</head>
<body>
<table
class="table"
border="1">
<tr>
<th>ID</th>
<th>发布者</th>
<th>内容</th>
<th>发布时间</th>
<th>操作</th>
</tr>
<foreach name=‘board‘
item=‘b‘>
<tr>
<td>{$b.id}</td>
<td>{$b.username}</td>
<td>{$b.content}</td>
<td>{$b.time|date=‘y-m-d
H:i‘,###}</td>
<td><a
href="{:U(‘admin.php/MsgManage/delete‘,array(‘id‘ =>
$b[‘id‘])),‘‘}">删除</a></td>
</tr>
</foreach>
//新增tr代码短
<tr>
<td
colspan=‘5‘
align=‘center‘>
//将5个单元格合并,并且居中显示
{$page}
//显示控制器中$this->page内容
</td>
</tr>
</table>
</body>
</html>