Home > PHP Framework > YII > body text

How to use Ueditor in Yii?

Guanhui
Release: 2020-06-09 14:59:55
Original
2949 people have browsed it

How to use Ueditor in Yii?

Yii How to use Ueditor?

First create a new public directory and uploads directory in the entry file directory;

Then download Ueditor, unzip it to the public directory;

Then import the "ueditor for yii2" library, and define a custom upload directory;

"imagePathFormat": "/uploads/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}",  
 "scrawlPathFormat": "/uploads/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}"
Copy after login

Finally, introduce it in the view and use it.

<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
//引入百度编辑器
$this->registerJsFile(&#39;@web/public/ueditor/ueditor.config.js&#39;);//注册自定义js
$this->registerJsFile(&#39;@web/public/ueditor/ueditor.all.min.js&#39;);
$this->registerJsFile(&#39;@web/public/ueditor/lang/zh-cn/zh-cn.js&#39;);
?>
<script>
 $(function(){
    var ue = UE.getEditor(&#39;editor&#39;);
 })
</script>
<style>
    .inline .radio,.inline .checkbox{display: inline-block;margin: 0 5px;}
    #editor{margin-top: 20px;padding:0;margin:20px 0;width:100%;height:auto;border: none;}
    
</style>
<?php $form=ActiveForm::begin([
        &#39;id&#39;=>&#39;upload&#39;,
        &#39;enableAjaxValidation&#39; => false,
        &#39;options&#39;=>[&#39;enctype&#39;=>&#39;multipart/form-data&#39;]
    ]);
?>
    <?= $form->field($model,&#39;title&#39;)->textInput();?>
    <?= $form->field($model, &#39;image&#39;)->fileInput();?>
    <?= $form->field($model,&#39;content&#39;)->textarea([&#39;rows&#39;=>6,&#39;id&#39;=>&#39;editor&#39;,&#39;class&#39;=>&#39;col-sm-1 col-md-12&#39;]);?>
    <?=  Html::submitButton(&#39;提交&#39;, [&#39;class&#39;=>&#39;btn btn-primary&#39;,&#39;name&#39; =>&#39;submit-button&#39;]) ?>

<?php ActiveForm::end();?>
Copy after login

Recommended tutorial: "Yii Tutorial"

The above is the detailed content of How to use Ueditor in Yii?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template