合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
插件后台编写其实是固定套路写法 cmf在初次激活插件的时候就已经有了几个按钮 如图所示 ![](https://box.kancloud.cn/514769e80cce87a8bf8f154adb8a22d1_1594x51.png) 这个按钮的链接直接指向到了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('删除成功!'); } } ~~~ ![](https://box.kancloud.cn/514769e80cce87a8bf8f154adb8a22d1_1594x51.png) ![](https://box.kancloud.cn/058262943432669b5bdca6d30f47ed2d_1647x225.png) ![](https://box.kancloud.cn/624cd51beb1b8ce0ba40a91c3fdbf3ff_1648x400.png) ![](https://box.kancloud.cn/b9e82a8e8955d26b5698cfd3c7e0007b_1610x326.png) ![](https://box.kancloud.cn/b96d854ab243b695b23b96fa2fd1248d_1626x234.png) > 首先感谢WelkinVan 他写的《ThinkCMF5从入门到精通》给了我很多帮助 > 点击去《[ThinkCMF5从入门到精通](https://ihavenolimitations.xyz/welkinvan/thinkcmf5)》 >