Yii2 integrates Baidu editor umeditor and yii2 integrates umeditor

Source: Internet
Author: User

Yii2 integrates Baidu editor umeditor and yii2 integrates umeditor

Author: White Wolf Source: www. manks. top/article/yii2_umeditor

The copyright of this article belongs to the author. You are welcome to repost this article, but you must keep this statement without the author's consent and provide the original article connection clearly on the article page. Otherwise, you will be entitled to pursue legal liability.

In actual work, similar News, articles, and other development work will inevitably not be encountered. This requires the operation staff to release the work. However, some friends, in order to save trouble, OK. It is online. My sister from other people is trying it out. Hey, you have published a big article for me.textareaEven if you're done, you don't want to be able to publish a piece of news. Let's talk about it next.Yii2How is the framework integrated with Baidu editor?umeditor.

umeditorWhat is it?ueditor, YouumeditorIs it pirated dongdongnan?umeditorIn other words, the mini version is used.ueditorAccording to Baidu official statement, it is actually the "short soft and small" in the editor, but the feature is incomplete. Ke, let's get back to the question.

First, let's download a mini ueditor on the official website.umeditorYes.um editor.

Download and decompress the package to the project root directory. /cssThe directory is namedumeditorThe specific location can be referenced later.

Step 2: Expandbackend\assets\AppsetClass, oh, why do we need to expand this stuff?umeditorThe integration of what relationship leader, half-way to kill a process of gold. The purpose of extending this class file here is to facilitate the introduction of this class file in the file.css jsFile drop.

Very simpleAppsetAdd the following two methods to the method:

// Define the JS method to be loaded as needed. Pay attention to the loading order in the final public static function addScript ($ view, $ jsfile) {$ view-> registerJsFile ($ jsfile, [AppAsset :: className (), 'desc' => 'backend \ assets \ appasset']);} // defines the On-Demand Loading css method, note that the loading sequence is in the final public static function addCss ($ view, $ cssfile) {$ view-> registerCssFile ($ cssfile, [AppAsset: className (), 'desc' => 'backend \ assets \ appasset']);}

Next, follow the configuration below.

First, let's assume there is an articlearticleTable with a contentcontentThe field must be displayed as the Baidu editor.

Followyii2According to the form model, we modifyarticle\_form.phpFilecontentField

<?= $form->field($model, 'content')->textarea(['style' => 'width:760px;height:500px;']) ?>

This file is introducedAppsetClass and introduce relatedCss jsThe file is as follows:

    use backend\assets\AppAsset;    AppAsset::register($this);    AppAsset::addCss($this,'/css/umeditor/themes/default/css/umeditor.css');    AppAsset::addScript($this,'/css/umeditor/umeditor.config.js');    AppAsset::addScript($this,'/css/umeditor/umeditor.min.js');    AppAsset::addScript($this,'/css/umeditor/lang/zh-cn/zh-cn.js');

Then you only need to register the followingjsCode

    <?php $this->beginBlock('js-block') ?>        $(function () {            var um = UM.getEditor('article-content', {            });        });    <?php $this->endBlock() ?>    <?php $this->registerJs($this->blocks['js-block'], \yii\web\View::POS_END); ?>

Aboutarticle-contentThis is the target object to be bound, that isContent.article-contentIs the current object'sidId.

OK. The Baidu editor is basically integrated here. Now, add an article and try again. Remember to update it to see if there is any content in the editor.

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.