日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

thinkphp 编辑器kindeditor

發布時間:2023/12/10 php 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。