In the previous article to introduce how to integrate Baidu editor Umeditor in Yii2 and how to solve umeditor upload picture problem.
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 install redactor.
You can refer to Https://github.com/yiidoc/yii2-redactor for installation. A lot of beginners do not like English, if you click on the link to refer to the installation of the GitHub, I hope you come back to see the entire installation process should be the necessary attention points.
1, we like them, the use of composer installation can be.
2. Add Configuration Items
' Modules ' => ['
redactor ' => ['
class ' => ' Yii\redactor\redactormodule ', ' uploaddir ' => '
upload directory ' ,
' uploadurl ' => ' pictures accessible address ',
' imageallowextensions ' =>[' jpg ', ' png ', ' gif ']
]
,
The first attention point, the default upload file saved in the root directory of the uploads, if you want to change the file save directory, modify the configuration item uploaddir can, and you need to modify uploadurl to ensure that the picture can be accessed. 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 like this
<?= \yii\redactor\widgets\redactor::widget ([' Model ' => $model, ' attribute ' => ' content '])?>
4, which upload class with a set of redactor, but you say your upload class need to rewrite, you can, just like the following 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, configure the language or plug-in, like the fourth step, add Lang and plugins configuration items to the Clientoptions item, if you want to ask what are the plugins, open the directory \vendor\yii2-redactor\assets\ Plugins can have a glimpse of the style.
6, picture upload attention, because redactor is introduced by the module, if your project contains rights management, remember to add permissions Oh.
7, forget a big premise, to ensure that your PHP support FileInfo expansion. Open the php.ini file and remove the semicolon in front of the FileInfo
The above is a small series to introduce the YII2 integrated Rich Text Editor Redactor example tutorial, I hope to help you!