Yii integration ueditor

Source: Internet
Author: User

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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.