## 插件控制器写法: 在插件`controller`目录下创建`IndexController.php`文件,内容如下: ```php <?php // +---------------------------------------------------------------------- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] // +---------------------------------------------------------------------- // | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. // +---------------------------------------------------------------------- // | Author: Dean <zxxjjforever@163.com> // +---------------------------------------------------------------------- namespace plugins\demo\controller; //Demo插件英文名,改成你的插件英文就行了 use cmf\controller\PluginBaseController; use plugins\Demo\Model\PluginDemoModel; use think\Db; class IndexController extends PluginBaseController { function index($id) { $users = Db::name("user")->limit(0, 5)->select(); $demos=PluginDemoModel::all(); // print_r($demos); $this->assign("users", $users); return $this->fetch("/index"); } } ``` ## 插件url生成 插件url生成方法,cmf_plugin_url(); ```php cmf_plugin_url($url,$param,$domain) ``` ### 功能: 生成访问插件的url ### 参数: `$url`: url 格式:插件名://控制器名/方法 `$param`:额外参数,默认为空数组 `$domain`:是否添加域名,默认false ### 返回: 类型url ### 模板使用: ```php {:cmf_plugin_url('Demo://Index/index',array('id'=>2),true)} {:cmf_plugin_url('Demo://List/index',array('id'=>2))} ```