One, before using the preparation.
Please make sure you have established a thinkphp site project before use.
1,Keditor.class.php and JSON.class.php are editor extension class files that copy them to the Thinkphp\lib\org\net directory of your site project.
2,the editor directory is The core package of Kindeditor. Copy it to the public directory of your project (and the public at the same level as the portal file ), and and then create a Upload directory. Used to store images uploaded using the editor.
3,KeditorAction.class.php is the editor's upload image function and browse remote picture function, copy it to your project's lib\action directory.
Second, the invocation of the object
To invoke the object in the Controller method:
Import ("ORG.Net.Keditor"), $ke =new keditor (), $ke->id= "content";//Specify TEXTAREA id$keshow= $ke->show ();//Generate JS code $this-> Assign ("Keshow", $keshow); $this->display ();
Display the editor in the appropriate template file for the method:
Above is the simplest method of invocation, and the extended class has many properties and methods. To achieve a more perfect function, read on.
Third, the properties of the object
I divide the attributes into two kinds. One isKindeditorcomes with properties, one is to extend the new attribute. Let's say you used it once.Kindeditor, you should knowKindeditoritself hasID, items, width, height, aftercreate, etc. -a property. These properties can now be usedPHPDirect definition, for example definitionID:$ke->id="Content",Define width:$ke->width="700px";I'll start with the object new property.
New properties for the object:
1. Jspath: DefiningKindeditorthe coreJSfile. The default value is/public/editor/Kindeditor.js, let's say yourEditorThe directory is not placed inPublibYou need to specify this property,as$ke->jspath="/kind/kindeditor.js";
2,form:Specify the form to submit ( from) ofID. The tacit feelingForm1, this attribute is a combination ofCtrl+enterthe Commit function is used. For example, one of your editors is placed on the formIDto be"Formid", in order to achieveCtrl+enterSubmitFormidform. Need to define$ke->form="Formid".
Ctrl+enter The submit feature also sets additional properties. Explained later.
3. imgid: Specifies the hidden domain IDthat holds the image address. Tacit feel img.
The editor uploads one image per upload. The image address is stored in the hidden field. When you add data to a database, you can also save the data in this hidden field to the database field. When the data is deleted. First read the database stored in the image address, to delete. The delete procedure simply calls the object'sThe Delimg method is possible. This method is explained in detail later. This will delete the content at the same time to delete the image.
Self-brought properties:
1,Items: Configure the Editor's toolbar to define methods such as
$ke->items= "[' Source ', ' | ', ' fullscreen ', ' undo ', ' Redo ', ' print ', ' cut ', ' copy ', ' Paste ']";
I have addedLittlekeywords, the ability to define a streamlined model editor at a high speed. Usage$ke->items="Little";
2,Aftercreate: Sets the callback function that is run after the editor is created, defining methods such as
$ke->aftercreate= "function (ID) {
Alert (' Successfully created ' +id)
}”;
I have addedCtrlenterkeywords that can be defined at high speedCtrl+enterto submit a form, use:
$ke->aftercreate= "Ctrlenter";
Need to define at the same time$ke->form="FormName",FormNamechange to the form where you have the editorID.
3. Resizemode:2or1or0,2you can drag to change the width and height. 1can only change height. 0cannot be dragged. Define methods such as:$ke->resizemode=1;Note that property values for numeric types are not placed in the argument, such as$ke->resizemode="1";It is wrong to define this.
4,Allowfilemanager:trueorfalse,truethe Browse Server picture feature is displayed (click the Upload image button to see this feature). Define methods such as
$ke, Allowfilemanager=ture;
Note that the attribute value is not placed in the argument when it is a Boolean value.
5,IMAGEUPLOADJSON Specifies the server-side program for uploading pictures, the default value is/index.php/keditor/upload
6. Filemanagerjson: Specifies the server-side program to browse remote pictures.
The default value is/index.php/keditor/filemanager
Note: Before you copied theKeditorAction.class.phpIt is for uploading images and browsing remote images. In the fileUploadmethod defines the upload image processing process, the fileFileManagermethod defines the process of browsing a picture. You can add inferred permissions to these two methods of code, implementing only the administrator ability to upload pictures or browse pictures. You can also not use the defaultKeditorAction.class.php, customize the upload process and browse the image processing process. Then you need to define it again .The Imageuploadjson property value and the Filemanagerjson property value. The custom process is explained later.
There are other self-brought properties. I will not list them all. You can viewKindeditorOfficial Documents
Http://www.kindsoft.net/doc.php?cmd=config
Attention. Numeric type or Boolean type attribute value, do not put in the argument. Other attribute values are placed in the argument, the format of the property value andKindeditorThe same format as itself.
Four-object method.
1. upload. Upload a picture.
This method is used during the editor upload image processing process, using:
Import ("ORG.Net.Keditor"); Keditor::upload ('./public/upload/', '/public/upload/', array (' gif ', ' jpg ', ' jpeg ', ' PNG ', ' BMP '), 1000000);
The upload method has three of the parameters. In turn, yes. "Upload picture folder", "Picture Display Address", "agree to upload image format", "consent of picture size (unitKB) "
Upload Picture folder: Default value "./public/upload/" (note PublicThere is a "dot" symbol in front of it. is the relative address used, not the absolute address), the Upload Image folder address is equivalent to processing files.thinkphp All the code is executed through the portal file, so the address is actually relative to the entry file.
Show Picture address: Default value "/public/upload" (usually an absolute address). If we upload a picture. The server-side generated picture is named 12345.gif. Upload will show the image address is /public/upload/12345.gif , because we use an absolute address, so the content of the editor published no matter where the site, the picture can be displayed normally.
Agree to upload the image format: Define an array. The default value is Array (' gif ', ' jpg ', ' jpeg ', ' PNG ', ' BMP ')
Agreed picture size: The default value is 1000000. Unit is BK.
2,FileManager. Browse the pictures of the server. This method is used during browse picture processing. Usage:
Import ("ORG.Net.Keditor"); Keditor::filemanager ("./public/upload/", "/public/upload/", Array (' gif ', ' jpg ', ' jpeg ', ' PNG ', ' bmp '));
The parameters are: "Browse Pictures Folder", "Picture Display Address", "Consent to browse image format", andUploadmethod, the Browse Pictures folder is a relative address. The image display address is considered an address.
3,Delimg: Delete images uploaded through the editor. This method is typically used when you delete database data.Import ("ORG.Net.Keditor"); Keditor::d elimg ($imgfield);//$imgfield is usually the field where your database holds the image address.
4,Show:Returns the generatedJSCode. This method is typically used in the controller that displays the editor.
The show method can use a parameter to define the kindeditor self-band property.
Such as:
Import ("ORG. Net.keditor "); $ke =new keditor (); $ke->show (" {ID: "Content", Width: ' 700px '; height: "300px"; Imgid: "img"} ");
Not recommended forShowdefinition of the transfer methodKindeditorproperty. ShowThe transfer method cannot be definedJspathand theformtwo new station properties. Nor can I useLittleand theCtrlenterkeywords.
thinkphp Editor Extension class Kindeditor usage