Brief analysis of YII2 integrated Rich Text Editor Redactor example Tutorial _php instance

Source: Internet
Author: User
In the previous article, we introduced how to integrate Baidu editor Umeditor in Yii2 and how to solve the problem of umeditor uploading pictures.

Today we're going to talk about YII2 integration another powerful and easy-to-use Rich Text editor redactor, personally feel redactor than Baidu editor easy to use OH

Redactor has the official YII2 plug-in package, the practicality is also very strong.

First of all, we are not impatient, first to install redactor.

You can refer to Https://github.com/yiidoc/yii2-redactor for installation. There are a lot of novice people who don't like English, if you click on the link to refer to the installation on GitHub, I hope you will come back and see the necessary points of attention throughout the installation process.

1, we like them, the use of composer installation can be.

2. Adding Configuration Items

' Modules ' = [' redactor ' and ' = ' class ' = ' Yii\redactor\redactormodule ', ' uploaddir ' + ' upload directory ', ' Uploadurl ' =& Gt ' Picture accessible address ', ' imageallowextensions ' =>[' jpg ', ' png ', ' gif '],],

The first note, the default upload file is saved in the root directory of uploads, if you want to change the file save directory, modify the configuration item uploaddir can, and you need to modify the Uploadurl to ensure that the image is accessible. 3, if your view is Activefield type, the following configuration applies to you

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

But if your form is not built with Yii's own build, you should configure it as follows

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

4, which upload class with a redactor set, but you say your upload class need to rewrite, also can, just like the following to add a few configuration can

<?= $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, configuration language or plug-in, like the fourth step, add Lang and plugins configuration items in the Clientoptions item, if you want to ask what plugins, open the directory \vendor\yii2-redactor\assets\ Plugins can be a glimpse of style.

6, picture upload note, because redactor is introduced by the module, if your project contains rights management, remember to add permissions Oh.

7, forget a big premise, ensure that your PHP support FileInfo extension. Open the php.ini file and remove the semicolon in front of FileInfo

The above is a small series to introduce you to the YII2 integrated Rich Text Editor Redactor example Tutorial, we hope to help!

  • 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.