浅析Yii2集成富文本编辑器redactor实例教程,yii2redactor
浅析Yii2集成富文本编辑器redactor实例教程,yii2redactor
在上篇文章给大家介绍了如何在yii2中集成百度编辑器umeditor以及如何解决umeditor上传图片问题。
今天我们来谈谈yii2集成另外一个强大好用的富文本编辑器Redactor,个人觉得Redactor比百度编辑器好用哦
Redactor有官方的Yii2插件package,实用性也是很强的。
首先我们不急不躁,先进行安装Redactor。
可以参考https://github.com/yiidoc/yii2-redactor进行安装。有很多新手看不惯英文哈,如果你点击了链接参考了github上的安装,希望你再回来看看在整个安装过程中都要哪些必要的注意点。
1、我们跟他们一样,利用composer安装即可。
2、添加配置项
'modules' => [ 'redactor' => [ 'class' => 'yii\redactor\RedactorModule', 'uploadDir' => '上传目录', 'uploadUrl' => '图片可访问地址', 'imageAllowExtensions'=>['jpg','png','gif'] ], ],
第一个注意点,默认的上传文件保存在根目录下的uploads,如果你想更换文件的保存目录,修改配置项uploadDir即可,同时你需要修改uploadUrl保证图片可访问。3、如果你的view是ActiveField类型,下面的配置适用你
<?= $form->field($model, 'content')->widget(\yii\redactor\widgets\Redactor::className()) ?>
但是如果你的表单不是用yii自带的组建生成的,你应该像下面这样配置
<?= \yii\redactor\widgets\Redactor::widget([ 'model' => $model, 'attribute' => 'content' ]) ?>
4、其中上传类用的是redactor一套,但是你说你的上传类需要重写,也可以,只需要像下面这样加几个配置即可
<?= $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、配置语言或者插件,像第四步一样,在clientOptions项中添加lang和plugins配置项即可,如果你想问都有哪些plugins,打开目录\vendor\yii2-redactor\assets\plugins可以一睹风采。
6、图片上传注意了,因为redactor是以模块进行引入的,如果你的项目含有权限管理,记得添加权限哦。
7、忘记了一个大前提,保证你的php支持fileinfo扩展。打开php.ini文件去掉fileinfo前面的分号即可
以上所述是小编给大家介绍的Yii2集成富文本编辑器redactor实例教程,希望对大家有所帮助!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Have you ever faced any issues while transferring files that prevented you from doing so? Well, many Windows users have recently reported that they faced issues while copying and pasting files into a folder, where an error was thrown saying “The file name of the destination folder is too long”. Additionally, some other Windows users expressed frustration when opening any file and said "the file name or extension is too long" and they were unable to open the file. This disappoints users by not allowing them to transfer files to any other folder. While analyzing the issue, we have come up with a series of solutions that may help alleviate the issue and allow users to transfer files easily. If you are in a similar situation, please see this post for more information. Source: https

Many Windows users have recently reported that they were annoyed when Windows Defender SmartScreen warned users not to launch applications that were not recognized by Microsoft Windows and they had to click on the "Run anyway" option every time. Windows users are unsure what they can currently do to avoid or disable it. After researching the issue, we found that Windows Defender functionality on the system can be disabled through the Settings application or the Local Group Policy Editor or by adjusting the registry files. By doing this, users will no longer have to face the defender SmartScreen. If your system also encounters

There is no better way to write Python code than using an integrated development environment (IDE). Not only can they make your work simpler and more logical, they can also improve programming experience and efficiency. Everyone knows this. The question is, how to choose the best Python development environment among the many options.

C language is a basic and important programming language. For beginners, it is very important to choose appropriate programming software. There are many different C programming software options on the market, but for beginners, it can be a bit confusing to choose which one is right for you. This article will recommend five C language programming software to beginners to help them get started quickly and improve their programming skills. Dev-C++Dev-C++ is a free and open source integrated development environment (IDE), especially suitable for beginners. It is simple and easy to use, integrating editor,

Many Windows users have encountered the problem of being unable to log in to Windows 11/10 systems due to failed login attempts or multiple system shutdowns. Users are frustrated because there is nothing they can do about it. Users may forget their PIN code to log into the system, or experience lags when using or installing software, and the system may be forced to shut down multiple times. Therefore, we have compiled a list of the best available solutions that will undoubtedly help consumers solve this problem. To learn more, continue reading this article. Note: Before doing this, make sure you have your system's administrator credentials and Microsoft account password to reset your PIN. If not, wait an hour or so and try with the correct PIN

Python is a very easy to learn, powerful programming language. Python includes efficient high-level data structures, providing simple and efficient object-oriented programming. The learning process of Python is indispensable without an IDE or code editor, or an integrated development editor (IDE). These Python development tools help developers speed up development using Python and improve efficiency. An efficient code editor or IDE should provide plug-ins, tools and other features that can help developers develop efficiently. 1.VimVim can be said to be the best IDE for Python. Vim is an advanced text editor designed to provide the actual Unix editor 'Vi' functionality and support more and more complete features.

Title: Introduction to Go language development tools: List of essential tools In the development process of Go language, using appropriate development tools can improve development efficiency and code quality. This article will introduce several essential tools commonly used in Go language development, and attach specific code examples to allow readers to understand their usage and functions more intuitively. 1.VisualStudioCodeVisualStudioCode is a lightweight and powerful cross-platform development tool with rich plug-ins and functions.

Remember Windows MovieMaker on Windows 7? Since discontinuing Windows MovieMaker, Microsoft hasn't launched any real movie makers. On the other hand, they tried to revamp the Photos app with a small and lightweight built-in video editor. After a long time, Microsoft launched Clipchamp, a better video processor for all Windows 11 devices. In this article, we’ll take a deep dive into how to get everything from the Clipchamp app on your Windows 11 device. How to use Clipchamp – Detailed tutorials are available
