I found a lot of related information on the Internet, but it was not very detailed. After reading it, I finally wrote it out.
First, let's talk about my version.
Yii: 1.1.15
Ueditor: 1.4.3 utf8
It's not too late. Start now.
Download ueditor from the official website, decompress the package, and move the folder to the root directory of the yii project.
Then open ueditor. config. js to modify
Var URL = window. UEDITOR_HOME_URL | '/ueditor/'; // getUEBasePath (); original
Added ActiveForm. php to generate widgets for yii.
ActiveForm. php code
Class ActiveForm extends CActiveForm {public function ueditor ($ model, $ attribute, $ htmlOptions = array () {// get the name CHtml: resolveNameID ($ model, $ attribute, $ htmlOptions); $ attr = 'name = "'. $ htmlOptions ['name']. '"style = "'. $ htmlOptions ['style']. '"'; $ content = $ model-> content? $ Model-> content: ''; $ str = '<script type =" text/javascript "src ="/ueditor. config. js "> </script> '; $ str. = '<script type = "text/javascript" src = "/ueditor. all. min. js "> </script> '; $ str. = '<script id = "editor" type = "text/plain "'. $ attr. '> '.html _ entity_decode ($ content ). '</script>'; $ str. = '<script type = "text/javascript"> var ue = UE. getEditor (\ 'editor \ '); </script>'; return $ str ;}}
Finally, we need to use ueditor to load this widget.
$ Form = $ this-> beginWidget ('activeform', array ('id' => 'user-form', // Please note: When you enable ajax validation, make sure the corresponding // controller action is handling ajax validation correctly. // There is a call to invoke majaxvalidation () commented in generated controller code. // See class documentation of CActiveForm for details on this. 'enablesajaxvalidation '=> false,);?>
LabelEx ($ model, 'title');?>
TextField ($ model, 'title', array ('SIZE' => 30, 'maxlength' => 30, 'class' => 'text-input small-input');?>
Error ($ model, 'title');?>
LabelEx ($ model, 'description');?>
TextField ($ model, 'description', array ('SIZE' => 30, 'maxlength' => 30, 'class' => 'text-input small-input');?>
LabelEx ($ tmodel, 'content');?>
Ueditor ($ tmodel, 'content', array ('style' => 'width: 850px; height: 400px; '); // is the size of the text box limited?>
IsNewRecord? 'New': 'save', array ('class' => 'click');?>
EndWidget ();?>
I just learned YII. Here is just a demo which is relatively simple and may be implemented in a clumsy way. Let's take a look at it here. If you have a better way, let me know. Thank you ~