第4课:tp5中如何使用ueditor

tp5环境使用ueditor时,一般把它放在public目录下的static目录下

打开ueditor/php/config.json文件,需要重新设置图片保存的路径。上传的图片一般放在tp5的public目录下的uploads目录中

"imagePathFormat": "/tp5/public/uploads/image/{yyyy}{mm}{dd}/{time}{rand:6}",


"scrawlPathFormat": "/tp5/public/uploads/image/{yyyy}{mm}{dd}/{time}{rand:6}"


"snapscreenPathFormat": "/tp5/public/uploads/image/{yyyy}{mm}{dd}/{time}{rand:6}"


"catcherPathFormat": "/tp5/public/uploads/image/{yyyy}{mm}{dd}/{time}{rand:6}"

图片存放路径是相对于web根目录的,比如:

/tp5/public/uploads/image

表示图片存放在web根目录下的tp5/public/uploads/image文件夹下

下面我们实现一个简单的案例:发布一条新闻,保存到数据库中

数据表结构

页面参考代码

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" src="__STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<form action="{:url('addarticle')}" method="post">
    <div>
        <label>标题</label>
        <input type="text" name="title">
    </div>
    <div>
        <label>正文</label>
        <script id="editor" name="content" type="text/plain" style="width:1024px;height:500px;"></script>
    </div>
    <div>
        <input type="submit" value="保存">
    </div>
</form>
<script>
    var ue = UE.getEditor('editor', {
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });
</script>
</body>
</html>

控制器参考代码

<?php


namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Exception;

class Article extends Controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function addarticle()
    {
        $title = input('post.title');
        $content = input('post.content');

        $data = ['title'=>$title,'content'=>$content];
        try{
            Db::name('article')->insert($data);
            echo '添加成功';
        }catch (Exception $ex){
            $this->error('添加失败,' . $ex->getMessage());
        }

    }

}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李 书 明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值