文档
https://www.thinkcmf.com/doc5_1.html
创建插件目录
config.php(更多具体类型参数可查看文档)
<?php
return [
'limt' => [
'title' => '文章条数',
'type' => 'text',
'value' => 6,
'tip' => '文章随机条数'
],
];
插件类主文件
ListRandPlugin.php
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Rifty <[email protected]>
// +----------------------------------------------------------------------
namespace plugins\list_rand; //Demo插件英文名,改成你的插件英文就行了
use cmf\lib\Plugin;
use think\Db;
use think\Request;
//Demo插件英文名,改成你的插件英文就行了
class ListRandPlugin extends Plugin
{
public $info = [
'name' => 'ListRand', //改成你的插件英文就行了
'title' => '文章随机插件', //标题
'description' => '文章随机插件', //描述
'status' => 0, //关
'author' => 'xiaoying', //作者
'version' => '1.0' //版本号
];
public $hasAdmin = 0; //插件是否有后台管理界面
// 插件安装
public function install()
{
return true; //安装成功返回true,失败false
}
// 插件卸载
public function uninstall()
{
return true; //卸载成功返回true,失败false
}
//实现的list_rand钩子方法
public function listRand($param)
{
$config = $this->getConfig();
$this->assign($config);
echo $this->fetch('index');
}
}
插件视图
view文件夹下可写展示页面
同步插件钩子
在:/portal/app/portal/hooks.php 中添加数据:
'list' => [
"type" => 3,//钩子类型(默认为应用钩子;2:应用钩子;3:模板钩子;4:后台模板钩子)
"name" => '显示随机文章列表', // 钩子名称
"description" => "显示随机文章列表", //钩子描述
"once" => 0 // 是否只执行一次
],
安装插件
调用插件
<hook name="list_rand"/>