首先,去官网下载最新版的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

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-v4.1.3的更多相关文章

  1. 基于ThinkPHP的在线编辑器调用

    开源的在线编辑器有很多,比如FCKEditor,UEditor,Kindeditor等,调用方式也都大同小异 下面列举UEditor在线编辑器插件在ThinkPHP里面的应用 1.Ueditor下载地 ...

  2. thinkphp——通过在线编辑器添加的内容在模板里正确显示(只显示内容,而不是html代码)

    thinkphp编辑器回显问题如下: 解决办法如下: 对于编辑器发布的内容,前台模板显示为html的解决办法是: 在模板输出字段加入html_entity_decode()函数 也就是:PHP输出时的 ...

  3. 在线编辑器KindEditor的使用

    1.官网下载:点击进入 2.解压后目录说明 ├── asp asp示例 ├── asp.net asp.net示例 ├── attached 空文件夹,放置关联文件attached ├── examp ...

  4. 在线编辑器kindEditor

    操作文档:http://kindeditor.net/doc.php 文件下载

  5. jquery插件课程2 放大镜、多文件上传和在线编辑器插件如何使用

    jquery插件课程2 放大镜.多文件上传和在线编辑器插件如何使用 一.总结 一句话总结:插件使用真的还是比较简单的,引包,初始化,配置参数(json),配置数据(json),而后两步不是必须的.而且 ...

  6. 在线编辑器的使用-KindEditor

    第一种:KindEditor编辑器 步骤一:加载相应的核心的文件 下载地址:http://kindeditor.net/demo.php <link rel="stylesheet&q ...

  7. 将kindeditor在线编辑器制作成smarty插件

    在web开发中,在线编辑器是经常要用到的功能模块,虽说配置在线编辑器没有多大难度,但是每一次编写重复的代码,总是让人感觉不爽. 本篇,就来讲解一下,如何将kindeditor制作成smarty的一个自 ...

  8. 20个最强的基于浏览器的在线代码编辑器 - OPEN资讯

    20个最强的基于浏览器的在线代码编辑器 - OPEN资讯 20个最强的基于浏览器的在线代码编辑器

  9. jsp解决kindeditor在线编辑器struts图片上传问题

    1.下载 官网下载ckeditor,解压后去掉不需要的部分,仅需保留plugin,lang,theme文件夹,这三个文件夹中用不到的东西可以删除, 比如lang文件下存放所有语言文件js,仅仅 保留e ...

随机推荐

  1. IDEA使用笔记(三)——小齿轮的显示和隐藏(Autoscroll from Source)

    在玩快捷键的时候,不清楚自己操作了什么,突然间发现——能直接定位到当前可编辑文件的哪个小齿轮,不见了,找了一会也没弄出来,从网上搜索吧!也没看到对应的方法,后来自己耐下心来复盘自己的操作,终于发现了, ...

  2. sql的行转列(PIVOT)与列转行(UNPIVOT) webapi 跨域问题 Dapper 链式查询 扩展 T4 代码生成 Demo (抽奖程序)

    sql的行转列(PIVOT)与列转行(UNPIVOT)   在做数据统计的时候,行转列,列转行是经常碰到的问题.case when方式太麻烦了,而且可扩展性不强,可以使用 PIVOT,UNPIVOT比 ...

  3. php数组添加元素的方法

    PHP数组添加一个元素的方式: push(),  arr[], Php代码   $arr = array(); array_push($arr, el1, el2 ... eln); 但其实有一种更直 ...

  4. poj3041(最小顶点覆盖)

    链接:点击打开链接 题意:N*N的矩阵中有一些点代表陨石.每次仅仅能消灭一行或一列连,问须要多少次才干所有消灭 代码: #include <map> #include <queue& ...

  5. Struts2之数据标签(二)

    Struts2之数据标签(一):http://blog.csdn.net/u012561176/article/details/46848817 1.action标签:使用此标签能够同意在JSP页面中 ...

  6. weblogic+eclipse插件部署多个项目

    第一篇博客...上班时间不多废话,直接上图. 首先环境我就不说了,装好weblogic,eclipse,以及weblogic的插件. eclipse的weblogic插件能够从eclipse上的Hel ...

  7. A标签href属性详解--记录八

    1.去掉<a>标签的下划线 <ul style=" list-style-type:none; margin:0;color:Gray; font-size:11px;ma ...

  8. Vue(四):实例化第一个Vue应用

    实例化语法 var vm = new Vue({ // 选项 }) Vue 构造器中的内容 <!DOCTYPE html> <html> <head> <me ...

  9. WPF 项目升级错误

    今天将一个 WPF 项目从 .NET 4.0 升级至 .NET 4.6.1 时,出现一个错误: 错误        未知的生成错误"程序集"PresentationFramewor ...

  10. Windows 虚拟桌面工具 Desktops v2.0

    https://technet.microsoft.com/en-us/sysinternals/cc817881.aspx