1. Preparation before use.
Please make sure you have created a Thinkphp website project before using it.
1. Keditor.class.php and JSON.class.php are editor extension class files. Copy them to the ThinkPHPLibORGNet folder of your website project.
2. The editor folder is the core package of kindeditor. Copy it to the Public folder of your project (the Public at the same level as the entry file), and create an Upload folder under Public to store images uploaded using the editor.
3. KeditorAction.class.php is the editor’s image upload function and remote image browsing function. Copy it to the libAction folder of your project.
2. Object call
Call object in controller method:
import("ORG.Net.Keditor"); $ke=new Keditor(); $ke->id="content";//指定textarea的id $keshow=$ke->show();//生成js代码 $this->assign("keshow",$keshow); $this->display();
<html> <head>{$keshow}</head><!--输出js,建议放在head--> <body> </body> </html>
3. Object properties
I divide the attributes into two types, one is the kindeditor's own attributes, and the other is the extended new attributes. If you have used kindeditor before, you should know that kindeditor itself has 30 attributes such as id, items, width, height, afterCreate, etc. These attributes can now be defined directly using PHP, such as defining id: $ke->id="content" and defining width: $ke->width="700px"; Let me first talk about the new attributes of the object.
New properties of objects:
1. jspath: Define the core js file of kindeditor. The default value is /Public/editor/kindeditor.js. If your editor folder is not placed under Publib, you need to specify this attribute, such as $ke->jspath="/kind/ kindeditor.js”;
2. Form: Specify the id of the submitted form (from), the default is form1. This attribute is used in combination with the ctrl+enter submission function. For example, if your editor is placed in the form id "formid", you need to implement ctrl +enter submits the formid form, you need to define $ke->form="formid". The ctrl+enter submission function also needs to set other attributes, which will be explained later.
3. imgid: Specifies the hidden domain id where the image address is stored. The default is img. Every time the editor uploads an image, the image address will be stored in this hidden field. When adding data to the database, you can also save the data in this hidden field to the database field. When deleting data, first read the image address stored in the database and delete it. The deletion process only requires calling the delimg method of the object. This method will be explained in detail later. In this way, the purpose of deleting content and pictures is achieved.
Comes with attributes:
1. items: Configure the toolbar of the editor, defined as
$ke->items=”['source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste']";
I added the little keyword to quickly define a streamlined model editor, using the method $ke->items="little";
2. afterCreate: Set the callback function to be executed after the editor is created. The definition method is such as
$ke->afterCreate=”function(id){
alert(‘successfully created’+id)
}";
I added the ctrlenter keyword to quickly define ctrl+enter to submit the form. How to use:
$ke->afterCreate=”ctrlenter”;
At the same time, you need to define $ke->form="formname", and replace formname with the form id where your editor is located.
3. resizeMode: 2 or 1 or 0. When 2, you can drag to change the width and height. When 1, you can only change the height. When 0, you cannot drag. The definition method is as follows: $ke->resizeMode=1; Note that numeric attribute values should not be placed in quotation marks, such as $ke->resizeMode="1"; such a definition is wrong.
4. allowFileManager: true or false. When true, the function of browsing server images is displayed (click the upload image button to see this function). The definition method is as follows:
$ke-> allowFileManager=ture;
Note that when the attribute value is a Boolean value, do not put it in quotes.
5. imageUploadJson specifies the server-side program for uploading images. The default value is /index.php/Keditor/upload
6. fileManagerJson: specifies the server-side program for browsing remote images,
The default value is /index.php/Keditor/filemanager
Note: The KeditorAction.class.php you copied before is used for uploading images and browsing remote images. The upload method in the file defines the process of uploading images, and the filemanager method in the file defines the process of browsing images. You can add code to determine permissions to these two methods so that only administrators can upload pictures or browse pictures. You can also define your own upload processing process and image browsing process instead of using the default KeditorAction.class.php. In this case, you need to redefine the imageUploadJson attribute value and fileManagerJson attribute value. The custom processing process will be explained in detail later.
There are other built-in attributes, so I won’t list them all. You can view the official documentation of kindeditor
http://www.kindsoft.net/doc.php?cmd=config
Note that attribute values of numeric type or Boolean type should not be placed in quotation marks. Other attribute values are placed in quotation marks, and the format of the attribute value is the same as the format of kindeditor itself.
四 对象的方法。
1,upload,上传图片。此方法在编辑器上传图片处理过程中使用,使用方法:
import("ORG.Net.Keditor"); Keditor::upload('./Public/Upload/','/Public/Upload/',array('gif','jpg','jpeg','png','bmp'),1000000);
import("ORG.Net.Keditor"); Keditor::filemanager("./Public/Upload/","/Public/Upload/",array('gif','jpg','jpeg', 'png', 'bmp'));
import("ORG.Net.Keditor"); Keditor::delimg($imgfield); //$imgfield 一般是你数据库存放图片地址的字段。
import("ORG.Net.Keditor"); $ke=new Keditor(); $ke->show(“{ id : ”content”, width: ‘700px’; height : ”300px”; imgid : ”img” }”);