附件下载功能_ThinkCMF插件

没有什么功能,是一个插件解决不了的。如果真有,那就是你技术不到位,继续加油吧!

ThinkCMF后台系统在文章编辑页面默认是存在附件的

mrfj.png

但是,你在上传文件之后会发现,并没有在前端页面中显示。

所以,今天来做一个的附件下载的插件功能。

制作插件

效果图:

fj.png

目录结构:

attachment

 ├─view

 │  └─widget.html

 └─AttachmentPlugin.php

AttachmentPlugin.php 文件

< php
// +----------------------------------------------------------------------
// | Wien Designs [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2018 Wien Designs All rights reserved.
// +----------------------------------------------------------------------
// | Author: Oliver Wien <oliverwien@yeah.net>
// +----------------------------------------------------------------------
namespace plugins\attachment;
use cmf\lib\Plugin;
use app\portal\model\PortalPostModel;
use think\request;
class AttachmentPlugin extends Plugin
{

    public $info = [
        'name'        => 'Attachment',
        'title'       => '附件下载',
        'description' => '附件下载功能插件',
        'status'      => 1,
        'author'      => 'Wien Designs',
        'version'     => '1.0',
        'demo_url'    => 'https://www.wien.ren',
        'author_url'  => 'https://www.wien.ren'
    ];

    public $hasAdmin = 0;

    public function install()
    {
        return true;
    }

    public function uninstall()
    {
        return true;
    }

    public function afterContent($param)
    {
        $config = $this->getConfig();
        $this->assign($config);
        $param = request::instance()->param();
        $PostObj = PortalPostModel::get($param['id']);

        if (isset($PostObj['more']['files'])) {
            $this->assign('files', $PostObj['more']['files']);
        } else {
            $this->assign('files', "");
        }
        echo $this->fetch('widget');
    }
}

widget.html 文件

<!-- 附件下载 -->
<style type="text/css">
.attachment >a{display:inline-block;margin:5px 10px 5px 0;color:#FFF;background:#337ab7;padding:2px 8px;}
</style>
<if condition="!empty($files)">
<div class="attachment">
    <h3 class="title-h3">附件</h3>
    <foreach name="files" item="vo">
    <a class="btn btn-primary btn-block" href="{:cmf_get_file_download_url($vo['url'])}">下载地址{$key+1}</a>
    </foreach>
</div>
</if>

这个插件同样非常的简单,有两个文件,AttachmentPlugin.php和widget.html,分别是插件类主文件和前台显示文件

css的样式,可根据个人喜好自己修改。如有什么问题,下方留言或者直接联系我!

Comments 0

0.152170s