search
HomeBackend DevelopmentPHP TutorialThinkphp编辑器扩充类kindeditor用法

Thinkphp编辑器扩展类kindeditor用法


一, 使用前的准备。
使用前请确认你已经建立好了一个Thinkphp站点项目。


1Keditor.class.php和JSON.class.php 是编辑器扩展类文件,将他们拷贝到你的站点项目的ThinkPHP\Lib\ORG\Net 目录下。


2editor目录是kindeditor的核心包。将其拷贝到你项目的Public目录下(和入口文件同级的那个Public,并在Public下再建立一个Upload目录。用于存放使用编辑器上传的图片。
3KeditorAction.class.php是编辑器的上传图片功能和浏览远程图片功能,将其拷贝到你项目的lib\Action 目录下。

二, 对象的调用
在控制器方法中调用对象:

import("ORG.Net.Keditor");$ke=new Keditor();$ke->id="content";//指定textarea的id$keshow=$ke->show();//生成js代码$this->assign("keshow",$keshow);$this->display();



在方法相应的模版文件里显示编辑器:

{$keshow}<!--输出js。建议放在head-->


上面的是最简单的调用方法,扩展类还有非常多属性和方法。要想实现更完美的功能,接着往下读。

三, 对象的属性
   我把属性分为两种。一种是kindeditor自带属性,一种是扩展新增属性。假设你曾经就使用过kindeditor,你应该知道kindeditor自身有id、items、width、height、afterCreate等等30个属性。这些属性如今能够用过php直接定义,比方定义id$ke->id=”content”,定义宽度:$ke->width=”700px”; 我先说对象新增属性。
对象的新增属性:
1jspath:定义kindeditor的核心js文件。默认值为/Public/editor/kindeditor.js ,假设你的editor目录没有放在Publib下须要指定此属性,$ke->jspath=”/kind/ kindeditor.js”;
2form指定提交的表单(from)的id。默觉得form1,这个属性是结合ctrl+enter提交功能使用的。比方有个你的编辑器放在表单id为 “formid”内,要实现ctrl+enter提交formid表单。须要定义$ke->form=”formid” 。

  ctrl+enter提交功能还要设置其它属性。后面再解说。


3imgid指定存放图片地址的隐藏域id。默觉得img

编辑器每上传一张图片。会把图片地址存储到该隐藏域。在向数据库加入数据时,能够把此隐藏域中的数据也保存到数据库字段中。在删除数据时候。先读取数据库存放的图片地址,进行删除。删除过程仅仅要调用对象的delimg方法就可以。此方法后面具体解释。这样就达到删除内容同一时候删除图片的目的。
自带属性:
1items:配置编辑器的工具栏,定义方法如
$ke->items=”['source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste']”; 
我添加了little关键词,能够高速定义一个精简模型的编辑器。用法$ke->items=”little”;
2afterCreate:设置编辑器创建后运行的回调函数,定义方法如
$ke->afterCreate=”function(id){
alert(‘成功创建’+id)
}”;
我添加了ctrlenter关键词,能够高速定义ctrl+enter提交表单,用法:
$ke->afterCreate=”ctrlenter”;
同一时候须要定义$ke->form=”formname”, formname换为你编辑器所在的表单id
3resizeMode:2102时能够拖动改变宽度和高度。1时仅仅能改变高度。0时不能拖动。定义方法如:$ke->resizeMode=1; 注意,数字类型的属性值不要放在引號中,如$ke->resizeMode=”1”;这么定义是错误的。
4allowFileManager:truefalsetrue时显示浏览server图片功能(点击上传图片button能够看到此功能)。定义方法如
$ke-> allowFileManager=ture;
注意,属性值为布尔值时不要放在引號中。
5imageUploadJson指定上传图片的server端程序,默认值为 /index.php/Keditor/upload
6fileManagerJson:指定浏览远程图片的server端程序,
默认值为/index.php/Keditor/filemanager 
注:之前你复制过的KeditorAction.class.php就是供上传图片和浏览远程图片使用的。文件内的upload方法定义了上传图片处理过程,文件内的filemanager方法定义了浏览图片的处理过程。你能够在这两个方法上增加推断权限的代码,实现仅仅有管理员才干上传图片或浏览图片。你也能够不使用默认的KeditorAction.class.php,自定义上传处理过程和浏览图片处理过程。则是你须要又一次定义imageUploadJson属性值和fileManagerJson属性值。 自定义处理过程,后面具体解释。
还有其它自带属性。我就不一一列举了。大家能够查看kindeditor官方文档
http://www.kindsoft.net/doc.php?cmd=config
注意。数字类型或布尔类型的属性值,不要放在引號内。其它属性值放在引號中,属性值的格式和kindeditor自身格式一样。



四 对象的方法。
1upload。上传图片。

此方法在编辑器上传图片处理过程中使用,用法:

import("ORG.Net.Keditor");Keditor::upload('./Public/Upload/','/Public/Upload/',array('gif','jpg','jpeg','png','bmp'),1000000);


 upload方法有三个參数。依次是。“上传图片文件夹”,“图片显示地址”,“同意上传图片格式”,“同意的图片大小(单位kb)”
上传图片文件夹:默认值“./Public/Upload/”(注意Public前面有个“点”符号。是使用的相对地址,不可使用绝对地址),上传图片文件夹地址是相当于处理文件的。

Thinkphp全部的代码都是通过入口文件执行的,所以这个地址事实上是相对于入口文件的。
显示图片地址:默认值“/Public/Upload”(通常是绝对地址)。如果我们上传了一张图片。server端生成的图片名为 12345.gif。上传会显示的图片地址则为/Public/Upload/12345.gif ,由于我们使用的是绝对地址,所以编辑器公布的内容无论在站点的哪儿,图片都能正常显示。


同意上传的图片格式:定义一个数组。默认值为array('gif','jpg','jpeg','png','bmp')
同意的图片大小:默认值为,1000000 。单位是bk
2filemanager。浏览server的图片。此方法在浏览图片处理过程中使用。用法:

import("ORG.Net.Keditor");Keditor::filemanager("./Public/Upload/","/Public/Upload/",array('gif','jpg','jpeg', 'png', 'bmp'));


參数依次是:“浏览图片文件夹”,“图片显示地址”,“同意浏览的图片格式”,和upload方法一样,浏览图片文件夹是相对地址。图片显示地址是认为地址。

3delimg:删除通过编辑器上传的图片。此方法一般在你删除数据库数据时使用。

import("ORG.Net.Keditor");Keditor::delimg($imgfield);//$imgfield 通常是你数据库存放图片地址的字段。<p></p>



4show返回生成的js代码。此方法一般在显示编辑器的控制器中使用。


show方法能够使用一个參数定义kindeditor自带属性。

如:

import("ORG.Net.Keditor");$ke=new Keditor();$ke->show(“{id : ”content”,width: ‘700px’;height : ”300px”;imgid : ”img”}”);


不建议用show传參方式定义kindeditor属性。show传參方式不能定义jspathform两个新站属性。也不能使用littlectrlenter关键词。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools