這篇文章給大家分享的是有關Yii使用Ueditor的方法的內容。小編覺得挺實用的,因此分享給大家做個參考。一起跟隨小編過來看看吧。
Yii 如何使用 Ueditor ?
首先在入口文件目錄下新建public目錄和uploads目錄;
然后下載Ueditor,解壓到public目錄下;
接著引“ueditor for yii2”庫,并定義自定義上傳目錄;
"imagePathFormat": "/uploads/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"scrawlPathFormat": "/uploads/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}"最后在視圖中引入使用即可。
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
//引入百度編輯器
$this->registerJsFile('@web/public/ueditor/ueditor.config.js');//注冊自定義js
$this->registerJsFile('@web/public/ueditor/ueditor.all.min.js');
$this->registerJsFile('@web/public/ueditor/lang/zh-cn/zh-cn.js');
?>
<script>
$(function(){
var ue = UE.getEditor('editor');
})
</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([
'id'=>'upload',
'enableAjaxValidation' => false,
'options'=>['enctype'=>'multipart/form-data']
]);
?>
<?= $form->field($model,'title')->textInput();?>
<?= $form->field($model, 'image')->fileInput();?>
<?= $form->field($model,'content')->textarea(['rows'=>6,'id'=>'editor','class'=>'col-sm-1 col-md-12']);?>
<?= Html::submitButton('提交', ['class'=>'btn btn-primary','name' =>'submit-button']) ?>
<?php ActiveForm::end();?>感謝各位的閱讀!關于Yii使用Ueditor的方法就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。