Yii 如何使用 Ueditor ?

Yii 如何使用 Ueditor ?,第1张

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教程》

以上就是Yii 如何使用 Ueditor ?的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/700836.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-23
下一篇 2022-04-23

发表评论

登录后才能评论

评论列表(0条)

保存