ThinkPHP3.2中引用Ueditor

ThinkPHP3.2中引用Ueditor,过程比较简单,这里给出一个示例,方便大家参考。更多更详细的内容请参考Ueditor的官网

在百度中搜索下载Ueditor。

1、将Ueditor的资源文件放在ThinkPHP应用的/Admin/Home/Public/目录下面


2、修改该目录下 ueditor.config.js中如下语句:
原本是这个样子


修改之后:



因为这个URL指向Ueditor资源文件的位置,所以配置一下。我上面的配置是绝对路径。配置的时候建议参考浏览器console中资源文件引用报错信息来改,比较简单。

3、在视图VIEW页面,也就是html页面中正确引入这些文件

3.1 在入口文件index.php中定义变量

3.2 在资源文件中引入js文件,config.js文件一定要先引入



4、在需要使用Ueditor的地方,引入Ueditor文件



5、初始化Ueditor的内容

var ue1 = UE.getEditor('editor1');
 ue1.ready(function() {
     ue1.setContent('{$info1.content}');
 });

6、获取Ueditor的内容并提交到后台

      $("#submit-content2").click(function(e){
            e.preventDefault(); 
            var content = null;
            ue2.ready(function(){
                content = ue2.getContent();
            })
            var data = {};
            data.editorValue = content;
            data.name = "content2";
            console.log(data)
            $.ajax({
                type:"post",
                url:"{$smarty.const.__SELF__}",
                data:data,
                success:function(){
                    alert("success!");
                },
                faild:function(){
                    alert("faild");
                },
                error:function(){
                    alert("error");
                }
            });
        });


7、编写对应页面的控制器,将后台的数据渲染到前端。

              if($_POST["name"]== "content2"){
                    $array = array(
                        'page-class'=>"balizhimei",
                        'page-title'=>"newstatus",
                        'type'=>"index-introduce",
                        'content'=> $_POST[editorValue],
                        'title'=>'新动态',
                        'data'=>time(),
                    );
                    $id = 9;
                    // $z = $content->add($array);
                    $z = $content ->where("id = $id")->save($array);
                }

8、至此配置结束。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值