插件控制器写法:

在插件controller目录下创建IndexController.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 cmf\controller\PluginBaseController;
  11. use plugins\Demo\Model\PluginDemoModel;
  12. use think\Db;
  13. class IndexController extends PluginBaseController
  14. {
  15. function index($id)
  16. {
  17. $users = Db::name("user")->limit(0, 5)->select();
  18. $demos=PluginDemoModel::all();
  19. // print_r($demos);
  20. $this->assign("users", $users);
  21. return $this->fetch("/index");
  22. }
  23. }

插件url生成

插件url生成方法,cmf_plugin_url();

  1. cmf_plugin_url($url,$param,$domain)

功能:

生成访问插件的url

参数:

$url: url 格式:插件名://控制器名/方法$param:额外参数,默认为空数组$domain:是否添加域名,默认false

返回:

类型url

模板使用:

  1. {:cmf_plugin_url('Demo://Index/index',array('id'=>2),true)}
  2. {:cmf_plugin_url('Demo://List/index',array('id'=>2))}

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