基于thinkphp的在线编辑器kindeditor

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

首先,去官网下载最新版的kindeditor,然后把里面asp,jsp,net,example的全删除,然后改名为editor放进public(最外层目录的public)文件夹里面。

在目录lib目录建立ORG文件夹(个人习惯用ORG存储公用类),建立一个共用类,editor.class.php

下面是这个类的具体代码

/*编辑器调用的初始化类

*

*/

class editor {

var $Width;

var $Height;

var $Value;

/* 此方法是编辑器的构造方法

*第一个参数,$Height是高度,不填默认是500px

*第二个参数,$Width是宽度,不填默认是700px

*第三个参数,$Value是编辑器默认内容,不填默认是“

欢迎使用编辑器


*

*/

function editor($Height="500px",$Width="700px",$V alue="

欢迎使用编辑器


") { $this->Value = $Value;

$this->Height = $Height;

$this->Width = $Width;

}

/*此方法是在线编辑器的调用

* 在需要编辑器的地方调用此函数

*/

function createEditor(){

return "";

}

/*使用在线编辑器必须在html之间调用此方法,才能正确调用,

* 内容主要都是script

*/

function usejs(){

$str=<<

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 //使用编辑器

Insert title here

{$usejs}

?>

{$editor}


相关文档
最新文档