插件后臺編寫其實是固定套路寫法
cmf在初次激活插件的時候就已經有了幾個按鈕 如圖所示

這個按鈕的鏈接直接指向到了AdminIndexController(固定名稱),這個控制器里面咱們可以隨便指向到任意模板了
我們要實現的是
后臺留言列表頁
后臺留言詳情頁
刪除功能
* * * * *
文件結構
│ config.php
│ GuestbookPlugin.php
│
├─assets
│ └─css
│ sy.guestbook.css
│
├─controller
│ AdminIndexController.php(新增)
│ IndexController.php
│
├─data
│ config.php
│ guestbook.sql
│
├─model
│ PluginSyGuestbookModel.php
│
├─validate
│ GuestbookValidate.php
│
└─view
│ admin_detail.html(新增)
│ admin_index.html(新增)
│ css.html
│ js.html
│ widget.html
│
└─public
head.html(新增)
scripts.html(新增)
* * * * *
admin_index.html
~~~
<!doctype html>
<html>
<head>
<include file="public/head"/>
<title>留言板后臺管理</title>
<meta name="description" content="">
<meta name="keywords" content="">
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a>留言板管理</a></li>
</ul>
<div class="common-form">
<form method="post" class="js-ajax-form" action="#">
<div class="table_list">
<table width="100%" class="table table-hover">
<thead>
<tr>
<th width="50">ID</th>
<th width="100">姓名</th>
<th width="130">時間</th>
<th width="120">操作</th>
</tr>
</thead>
<tbody>
<foreach name="guestbook" item="vo">
<tr>
<td>{$vo.id}</td>
<td>{$vo.name}</td>
<td>{:date('Y-m-d H:i',$vo['create_time'])}</td>
<td>
<a href="javascript:parent.openIframeLayer('{:cmf_plugin_url('Guestbook://AdminIndex/detail',['id'=>$vo['id']])}','{$vo.name}的留言詳細信息',{area:['60%','70%']});">查看</a> |
<a href="{:cmf_plugin_url('Guestbook://AdminIndex/delete',['id'=>$vo['id']])};" class="js-ajax-delete">刪除</a>
</td>
</tr>
</foreach>
</tbody>
</table>
<div class="pagination">{$page}</div>
</div>
</form>
</div>
</div>
<include file="public/scripts"/>
</body>
</html>
~~~
admin_detail.html
~~~
<!doctype html>
<html>
<head>
<include file="public/head"/>
<title>留言板后臺管理</title>
<meta name="description" content="">
<meta name="keywords" content="">
</head>
<body>
<div class="wrap">
<div class="guestbook-detail">
<h3>{$detail.name}的留言詳細信息
<small>{:date('Y-m-d H:i',$detail['create_time'])}</small>
</h3>
<table class="table table-bordered table-hover">
<tr>
<td width="15%">姓名</td>
<td>{$detail.name}</td>
</tr>
</table>
</div>
</div>
<include file="public/scripts"/>
</body>
</html>
~~~
public/head.html
~~~
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Set render engine for 360 browser -->
<meta name="renderer" content="webkit">
<!-- No Baidu Siteapp-->
<meta http-equiv="Cache-Control" content="no-siteapp"/>
<link rel="shortcut icon" href="__PLUGIN_TMPL__/public/assets/images/favicon.ico" type="image/x-icon">
<link href="__ADMIN_TMPL__/public/assets/themes/{:cmf_get_admin_style()}/bootstrap.min.css" rel="stylesheet">
<link href="__ADMIN_TMPL__/public/assets/simpleboot3/css/simplebootadmin.css" rel="stylesheet">
<link href="__STATIC__/font-awesome/css/font-awesome.min.css?page=index" rel="stylesheet" type="text/css">
<script type="text/javascript">
//全局變量
var GV = {
ROOT: "__ROOT__/",
WEB_ROOT: "__WEB_ROOT__/",
JS_ROOT: "static/js/"
};
</script>
~~~
scripts.html
~~~
<script src="__STATIC__/js/jquery.js"></script>
<script src="__STATIC__/js/wind.js"></script>
<script src="__STATIC__/js/bootstrap.min.js"></script>
<script src="__STATIC__/js/admin.js"></script>
~~~
controller/AdminIndexController.php
~~~
<?php
namespace plugins\guestbook\controller; //Demo插件英文名,改成你的插件英文就行了
use cmf\controller\PluginBaseController;
use plugins\guestbook\Model\PluginSyGuestbookModel;
class AdminIndexController extends PluginBaseController
{
//初始化,檢測是否可以管理
function _initialize()
{
$adminId = cmf_get_current_admin_id();//獲取后臺管理員id,可判斷是否登錄
if (!empty($adminId)) {
$this->assign("admin_id", $adminId);
} else {
header('HTTP/1.1 404 Not Found');
header('Status:404 Not Found');
$this->error('非法登錄!!');
}
}
//留言列表
function index()
{
$guestbookModel = new PluginSyGuestbookModel();
$guestbook = $guestbookModel->order("id DESC")->paginate(20);
// 獲取分頁顯示
$page = $guestbook->render();
$this->assign("guestbook", $guestbook);
$this->assign("page", $page);
return $this->fetch('/admin_index');
}
//查看留言詳細信息
function detail()
{
$id = $this->request->param('id', 0, 'intval');
$guestbookModel = new PluginSyGuestbookModel();
$detail = $guestbookModel->where(["id" => $id])->find();
$this->assign("detail", $detail);
return $this->fetch('/admin_detail');
}
//刪除留言
function delete()
{
$id = $this->request->param('id', 0, 'intval');
$guestbookModel = new PluginSyGuestbookModel();
$guestbookModel::destroy(['id' => $id]);
$this->success('刪除成功!');
}
}
~~~





> 首先感謝WelkinVan 他寫的《ThinkCMF5從入門到精通》給了我很多幫助
> 點擊去《[ThinkCMF5從入門到精通](http://www.hmoore.net/welkinvan/thinkcmf5)》
>
- php套路
- 套路之類結構
- thinkphp分塊解析之Collection
- thinkphp基礎之collection
- Collection在thinkphp中的運用
- thinkcmf模塊分析
- Controller按界面點擊順序排列表
- user模塊-Controller分析
- portal模塊-Controller分析
- admin模塊-Controller分析
- user模塊-腦圖
- portal模塊-腦圖
- admin模塊-腦圖
- cmf公共函數解析-common.php
- thinkcmf點滴記錄
- 自定義標簽詳解
- 插件
- 系統信息插件
- 插件演示插件
- 留言板插件
- 留言板1 建立胚胎
- 留言板1-1 數據庫變化
- 留言板1-2 自定義鉤子
- 留言板2 連接數據庫
- 留言板3 讀取后臺界面數據
- 留言板4 前端模板
- 留言板5 分離cssjs文件
- 留言板6 驗證
- 留言板7 圖形驗證碼
- 留言板8 后臺留言列表頁
- 留言板9 后記
- 評論插件
- 1 分析數據表
- 2 CommentModel.php
- 3 UserModel.php
- 4 DCommentPlugin.php
- 前端調用代碼
- 喜歡插件
- 1 分析
- 2 收藏功能
- 3 插件建模
- 4 數據庫設計
- 5 插入一條數據
- 多語言
- thinkphp多語言
- thinkcmf多語言