thinkphp 编辑器kindeditor
首先,去官网下载最新版的kindeditor,然后把里面asp,jsp,net,example的全删除,然后改名为editor放进public(最外层目录的public)文件夹里面
在目录lib目录建立ORG文件夹(个人习惯用ORG存储公用类),建立一个共用类,editor.class.php
下面是这个类的具体代码
<?php
/*编辑器调用的初始化类
*
*/
class editor {
var $Width;
var $Height;
var $Value;
/* 此方法是编辑器的构造方法
*第一个参数,$Height是高度,不填默认是500px
*第二个参数,$Width是宽度,不填默认是700px
*第三个参数,$Value是编辑器默认内容,不填默认是“<h2>欢迎使用编辑器</h2><br>”
*
*/
function editor($Height="500px",$Width="700px",$Value="<h2>欢迎使用编辑器</h2><br>") {
$this->Value = $Value;
$this->Height = $Height;
$this->Width = $Width;
}
/*此方法是在线编辑器的调用
* 在需要编辑器的地方调用此函数
*/
function createEditor(){
return "<textarea name='content1' style='width:$this->Width;height:$this->Height;visibility:hidden;'>$this->Value</textarea>";
}
/*使用在线编辑器必须在html<head></head>之间调用此方法,才能正确调用,
* 内容主要都是script
*/
function usejs(){
$str=<<<eot
<link rel="stylesheet" href="__PUBLIC__/editor/themes/default/default.css" />
<link rel="stylesheet" href="__PUBLIC__/editor/plugins/code/prettify.css" />
<script charset="utf-8" src="__PUBLIC__/editor/kindeditor.js"></script>
<script charset="utf-8" src="__PUBLIC__/editor/lang/zh_CN.js"></script>
<script charset="utf-8" src="__PUBLIC__/editor/plugins/code/prettify.js"></script>
<script>
KindEditor.ready(function(K) {
var editor1 = K.create('textarea[name="content1"]', {
cssPath : '__PUBLIC__/editor/plugins/code/prettify.css',
uploadJson : '__PUBLIC__/editor/php/upload_json.php',
fileManagerJson : '__PUBLIC__/editor/php/file_manager_json.php',
allowFileManager : true,
afterCreate : function() {
var self = this;
K.ctrl(document, 13, function() {
self.sync();
K('form[name=example]')[0].submit();
});
K.ctrl(self.edit.doc, 13, function() {
self.sync();
K('form[name=example]')[0].submit();
});
}
});
prettyPrint();
});
</script>
eot;
return $str;
}
/*取得在线编辑器的值并返回
*/
function getEditorContent(){
$htmlData = '';
if (!empty($_POST['content1'])) {
if (get_magic_quotes_gpc()) {
$htmlData = stripslashes($_POST['content1']);
} else {
$htmlData = $_POST['content1'];
}
return $htmlData;
}
}
}
代码注释都写的比较清楚了,然后在action建立个文件,是IndexAction.class.php
<?php
class IndexAction extends Action {
public function _initialize() {
header("Content-Type:text/html; charset=utf-8");
}
public function index(){
import("@.ORG.editor"); //导入类
$editor=new editor(); //创建一个对象
$a=$editor->createEditor(); //返回编辑器
$b=$editor->usejs(); //js代码
$this->assign('usejs',$b); //输出到html
$this->assign('editor',$a);
$this->display();
}
public function php(){
import("@.ORG.editor");
$editor=new editor();
$a=$editor->getEditorContent(); //获取编辑器的内容
$this->assign('a',$a);
$this->display();
// $this->success('数据添加成功!');
}
}
然后在tpl建立index文件夹,在里面建立2个html文件,
index.html //使用编辑器
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
{$usejs}
</head>
<body>
<form name="example" method="post" action="__URL__/php">
<?php //<textarea name="content1" style="width:700px;height:200px;visibility:hidden;"></textarea> ?>
{$editor}
<br />
<input type="submit" name="button" value="提交内容" /> (提交快捷键: Ctrl + Enter)
</form>
</body>
</html>
php.html //获取编辑器的内容
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
{$a}
</body>
</html>
thinkphp 编辑器kindeditor相关推荐
- php中使用kindeditor,Thinkphp编辑器扩张类kindeditor使用方法
Thinkphp编辑器扩展类kindeditor使用方法 一, 使用前的准备. 使用前请确认你已经建立好了一个Thinkphp网站项目. 1,Keditor.class.php和JSON.class. ...
- html编辑器kindeditor我的使用方法 (转载)
来自:http://www.cnblogs.com/authen/archive/2009/11/28/1612586.html html编辑器kindeditor我的使用方法 kindeditor在 ...
- PHP 编辑器 kindEditor 上传图片失败 解决方案
这个坑是原始巨坑,刚学PHP出来的时候,为这个问题鏖战了好几天,含泪将解决方案写出来,希望能帮到你们 问题 PHP 编辑器 kindEditor上传图片失败 解决方案 打开 kindEditor 的 ...
- 富文本编辑器 Kindeditor 的使用和 常见错误
富文本编辑器 Kindeditor 的使用和 常见错误 错误一 问题描述:批量图片上传弹窗中 没有添加图片按钮 原因以及解决:按钮资源(.swf)被拦截 错误二 问题描述:图片上传失败 原因分析:批量 ...
- php网页可视化编辑器,在线HTML可视化编辑器KindEditor | 严佳冬
可视化编辑器kindeditor简介 可视化编辑器kindeditor是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即所得编辑效果,开发人员可以用 KindEditor 把传统的多行文 ...
- 一款好用的文本编辑器KindEditor+PHP
1,一款好用的文本编辑器KindEditor 下载页面: http://www.kindsoft.net/down.php <!DOCTYPE html> <html lang=&q ...
- 手机html编辑器gb2312,所见即所得HTML编辑器 - KindEditor 2.4
所见即所得HTML编辑器 - KindEditor 2.4 程序名:KindEditor 版本:2.4 演示: [url]http://www.kindsoft.net/editor/demo.htm ...
- [原] 开源HTML文本编辑器--KindEditor
====================================================== 注:本文源代码点此下载 ================================= ...
- easyUI整合富文本编辑器KindEditor详细教程
原因 在今年4月份的时候写过一篇关于easyui整合UEditor的文章Spring+SpringMVC+MyBatis+easyUI整合优化篇(六)easyUI与富文本编辑器UEditor整合,从那 ...
最新文章
- 强化学习(五) - 时序差分学习(Temporal-Difference Learning)及其实例----Sarsa算法, Q学习, 期望Sarsa算法
- 我对虚拟化的认识(一)
- 在WPF应用程序中利用IEditableObject接口实现可撤销编辑的对象
- 第四范式入围Gartner新兴技术与趋势影响力雷达全球代表厂商
- 线性代数拾遗(一):线性方程组、向量方程和矩阵方程
- 合并果子(信息学奥赛一本通-T1369)
- Qt 学习笔记(5)绘图 五子棋游戏
- (14) 常用管理类软件需求征集 -- 组织机构管理
- 下载faceScrub人脸数据库 (多线程版本)
- IE8的样式兼容性适应方法【转】
- esp8266实验:搭建最小系统,刷nodemcu固件,dht11温度读取并上传服务器
- Oracle VM VirtualBox固定ip
- 2022年广东省安全员A证第三批(主要负责人)考试题及广东省安全员A证第三批(主要负责人)复审模拟考试
- 沪深股票的复权计算(复权因子的应用)
- 移动端布局三种视口_什么是视口?移动端浏览器中的3种视口
- web前端新手入门:全球互联网的发展史
- python中年大叔学编程_中年大叔学编程-我用Python保存金山词霸每日一句
- springboot+vue校园新闻网站(源码+说明文档)
- 投影仪显示服务器不能连接不上,极米投影仪常见故障和自助解决方案?
- TinyXML2 学习