ThinkPHP3.2中引用Ueditor
2016-06-14 23:18
477 查看
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、至此配置结束。
在百度中搜索下载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、至此配置结束。
相关文章推荐
- php中引用&的真正理解-变量引用、函数引用、对象引用
- PHP中构造函数和析构函数解析
- php面向对象学习
- laravel框架——学习笔记
- PHP留言小练习
- PHP中对数据库操作的封装
- laravel5.1框架下的控制器和页面跳转
- PHP_课堂总结笔记0614
- VMware推出TrustPoint产品,完善终端用户计算方案
- ThinkPHP报错处理
- AjAX(第3章 Ajax的简单例子(Ajax+PHP)
- ffmpeg学习3-- ffmpeg解码rtp流
- JHTP小结_第三章_类、对象、方法及字符串简介
- 笔记
- PHP面向对象——访问修饰符
- php 实现长连接
- php函数serialize()与unserialize()
- PHP_Cli模式初涉——转载一篇
- 全志平台TP驱动
- Thinkphp 关联关系一对多,取出数组