Analysis of Yii2 integration Rich Text Editor redactor instance tutorial, yii2redactor

Source: Internet
Author: User

Analysis of Yii2 integration Rich Text Editor redactor instance tutorial, yii2redactor

In the previous article, I introduced how to integrate the 100degree editor umeditor in yii2 and how to solve the problem of umeditor uploading images.

Today, let's talk about yii2 integrating another powerful and useful Rich Text Editor Redactor. I personally think Redactor is better than Baidu editor.

Redactor has the official Yii2 plug-in package, which is also very practical.

First, we will install Redactor first.

For more information, see https://github.com/yiidoc/yii2-redactor. Many new users are not familiar with English. If you click the link and refer to the installation on github, I hope you will come back to see the necessary precautions during the installation process.

1. We can use composer for installation just like they do.

2. Add configuration items

& Apos; modules & apos; = & apos; redactor & apos; = & apos; class & apos;, & apos; class & apos;, & apos;, & apos; redactor & apos ', 'uploadurl' => 'image access', 'imageallowextension' => ['jpg ', 'png', 'gif'],],

First, note that the default Upload File is stored in the uploads under the root directory. If you want to change the file storage directory, modify the configuration item uploadDir, at the same time, you need to modify the uploadUrl to ensure that the image is accessible. 3. If your view is of the ActiveField type, the following configuration applies to you:

<?= $form->field($model, 'content')->widget(\yii\redactor\widgets\Redactor::className()) ?>

However, if your form is not generated by yii, you should configure it as follows:

<?= \yii\redactor\widgets\Redactor::widget([ 'model' => $model, 'attribute' => 'content' ]) ?>

4. the upload class uses a set of redactor, but you say that your upload class needs to be rewritten. You only need to add several configurations as follows.

<?= $form->field($model, 'content')->widget(\yii\redactor\widgets\Redactor::className(), [ 'clientOptions' => [ 'imageManagerJson' => ['/redactor/upload/image-json'], 'imageUpload' => ['/redactor/upload/image'], 'fileUpload' => ['/redactor/upload/file'], 'lang' => 'zh_cn', 'plugins' => ['clips', 'fontcolor','imagemanager'] ] ]) ?>

5. Configure the language or plug-in. Just add the lang and plugins configuration items in the clientOptions item as in step 4. If you want to ask which plugins are available, open the directory \ vendor\ yii2-redactor \ assets \ plugins to see the style.

6. Pay attention to uploading images because redactor is introduced in modules. If your project contains permission management, remember to add permissions.

7. Forget the premise that your php supports fileinfo extension. Open the php. ini file and remove the semicolon before fileinfo.

The above is an example of Yii2 integrated Rich Text Editor redactor, which is introduced by the editor. I hope it will help 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.