插件后台管理控制器

  • 在插件类主文件里加hasAdmin为1的属性;

  • 默认后台管理控制器AdminIndex,默认方法index,不可更改

  • cmf_get_current_admin_id();可获取后台管理员id,可用于判断是否登录

在插件controller目录下创建AdminIndexController.php文件,内容如下:

  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: Dean <zxxjjforever@163.com>
  8. // +----------------------------------------------------------------------
  9. namespace plugins\demo\controller; //Demo插件英文名,改成你的插件英文就行了
  10. use think\Db;
  11. use cmf\controller\PluginBaseController;
  12. use plugins\Demo\Model\PluginDemoModel;
  13. class AdminIndexController extends PluginBaseController
  14. {
  15. function _initialize()
  16. {
  17. $adminId = cmf_get_current_admin_id();//获取后台管理员id,可判断是否登录
  18. if (!empty($adminId)) {
  19. $this->assign("admin_id", $adminId);
  20. } else {
  21. //TODO no login
  22. }
  23. }
  24. function index()
  25. {
  26. $users = Db::name("user")->limit(0, 5)->select();
  27. $demos = PluginDemoModel::all();
  28. // print_r($demos);
  29. $this->assign("users", $users);
  30. return $this->fetch('/admin_index');
  31. }
  32. }

原文: https://www.thinkcmf.com/docs/cmf/插件后台管理控制器.html