天天看點

thinkcmf插件開發

目錄

    • 文檔
    • 建立插件目錄
      • config.php(更多具體類型參數可檢視文檔)
      • 插件類主檔案
      • 插件視圖
    • 同步插件鈎子
    • 安裝插件
    • 調用插件

文檔

https://www.thinkcmf.com/doc5_1.html

建立插件目錄

thinkcmf插件開發

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檔案夾下可寫展示頁面

thinkcmf插件開發
thinkcmf插件開發

同步插件鈎子

在:/portal/app/portal/hooks.php 中添加資料:

'list' => [
        "type"        => 3,//鈎子類型(預設為應用鈎子;2:應用鈎子;3:模闆鈎子;4:背景模闆鈎子)
        "name"        => '顯示随機文章清單', // 鈎子名稱
        "description" => "顯示随機文章清單", //鈎子描述
        "once"        => 0 // 是否隻執行一次
    ],
           
thinkcmf插件開發

安裝插件

thinkcmf插件開發

調用插件