1、下载ueditor,在yii2目录的web文件夹下新建的public文件夹,把ueditor放入public下
2、在view下新建ueditor.php文件
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View引入相关js文件 */
<?=Html::jsFile(‘@web/public/ueditor/ueditor.config.js‘)?>
<?=Html::jsFile(‘@web/public/ueditor/ueditor.all.min.js‘)?>
<?=Html::jsFile(‘@web/public/ueditor/lang/zh-cn/zh-cn.js‘)?>
<?php $form = ActiveForm::begin([
‘id‘ => ‘upload‘,
‘enableAjaxValidation‘ => false,
‘options‘ => [‘enctype‘ => ‘multipart/form-data‘]
]);
?>
<?= $form->field($model, ‘content‘)->textarea([‘rows‘ => 100, ‘id‘ => ‘editor‘, ‘class‘ => ‘col-sm-1 col-md-12‘]); ?>
<?= Html::submitButton($model->isNewRecord ? ‘Create‘ : ‘Update‘, [‘class‘ => $model->isNewRecord ? ‘btn btn-success‘ : ‘btn btn-primary‘]) ?>
<?php ActiveForm::end(); ?>
<script type="text/javascript">
window.onload=function(){
var ue = UE.getEditor(‘editor‘);//把ueditor实例化到textarea表单上,注意getEditor()参数为表单id
}
</script>
3、
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-09 18:45:46